我有一个问题,我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;
}