لعب MP3 على iPhone SDK؟
-
18-09-2019 - |
سؤال
-(IBAction)musiconButtonClicked:(id)sender{
NSString *path = [[NSBundle mainBundle] pathForResource:@"NextRevIt" ofType:@"mp3"];
AVAudioPlayer* audioPlayer = [[AVAudioPlayer alloc ] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[audioPlayer play];
}
-(IBAction)musicoffButtonClicked:(id)sender{
[audioPlayer stop]; <----says this is undeclared?
}
يمكنني الحصول على الصوت للعب بشكل جيد، ولكن كيف أقوم بإجراء زر يتوقف الصوت؟
المحلول
ضع هذا في interface
كتلة في .h
.
AVAudioPlayer* audioPlayer;
سوف تحتاج إلى التحقق من وجود مثيل وإطلاق سراحها أيضا.
نصائح أخرى
لقد أعلنت AVAudioPlayer* audioPlayer
كطريقة متغير محلي. تغيير نطاق هذا المتغير إلى مستوى الفصل. يتبع دانيال أبيض اقتراح
لا تنتمي إلى StackOverflow