我有一个问题,我在视图AVAudioPlayer
中播放controller(appMusicViewController)
,我将会话设置为AVAudioSessionCategorySoloAmbient
,当我导航到其他视图时,它运行良好音乐在后台播放,但当我回到appMusicViewController
并触摸播放按钮时,它不会停止上一次播放,因此它会同时播放音乐。 appMusicViewController
如何知道最后AVAudioPlayer
分配的信息?
-(void)viewDidLoad
{
[super viewDidLoad];
playList=[[NSArray alloc] initWithObjects:@"David Keller - Klangkissen (Extended Version)",@"Karmon - Wowshit (Original Mix) HQ",@"Phonique - Feel What You Want Feat. Rebecca",@"Toky - About You (Original Mix)", nil]; // 4 SONGS
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategorySoloAmbient error: nil];
artWork=[[NSArray alloc] initWithObjects:@"David Keller - Klangkissen (Extended Version).jpg",@"Karmon - Wowshit (Original Mix) HQ.jpg",@"Phonique - Feel What You Want Feat. Rebecca.jpg",@"Toky - About You (Original Mix).jpg", nil];
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:[playList objectAtIndex:count] ofType: @"mp3"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:soundFilePath ];
myAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
myAudioPlayer.numberOfLoops=0;
myAudioPlayer.delegate=self;
myAudioPlayer.volume=self.volume.maximumValue/2;
}
- (IBAction)play:(id)sender
{
[myAudioPlayer play];
playing=YES;
}