سؤال

-(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 كطريقة متغير محلي. تغيير نطاق هذا المتغير إلى مستوى الفصل. يتبع دانيال أبيض اقتراح

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top