私はXcodeの初心者であり、xcodeをマスターした人からの経験が必要です。UIActionSheetで音楽を再生、一時停止、停止しようとしていますが、[一時停止]と[停止]ボタンをクリックしても停止しないか、[再生のみを一時停止]ボタンが機能します。誰かが助けてくれますか?これが私のコードです。
#import <AVFoundation/AVFoundation.h>
@interface MainViewController () <UIActionSheetDelegate,AVAudioPlayerDelegate>
@property(nonatomic,retain)AVAudioPlayer *playAudio;
@end
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *buttonTitle =[actionSheet buttonTitleAtIndex:buttonIndex];
NSURL *url =[NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/MusicName.mp3",[[NSBundle mainBundle] resourcePath]]];
NSError *error;
self.playAudio=[[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error];
if (buttonIndex==0) {
[self.playAudio play];
}
if ([buttonTitle isEqualToString:@"Pause"]) {
[self.playAudio pause];
}
if (buttonIndex==2) {
[self.playAudio stop];
}
}
- (IBAction)Music:(id)sender {
UIActionSheet *musicSheet =[[UIActionSheet alloc]initWithTitle:@"Choose" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Play",@"Pause",@"Stop", nil];
[musicSheet showInView:self.view];
}
。私はベトナム人なので、英語のスキルがあなたに私の言うことを理解するのを難しくすることができます。お時間をいただきありがとうございます。お返事をお待ちしております