我正在制作一款需要在循环中播放声音的Iphone应用。声音将来自HTTP链接,如下所示:
实际上有三个按钮循环,全部播放并停止。我可以做一次点击全部播放循环,但当我点击其他按钮应用程序将崩溃。我怎么能解决这个问题。我的代码是下面resultArrayFinal是一个全球阵列所有上述声音链接存储。
-(void)replayVedio
{
DataClass *obj=[DataClass getInstance];
NSURL *url = [NSURL URLWithString:obj.soundInfo];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[moviePlayer setControlStyle:MPMovieControlStyleDefault];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[moviePlayer prepareToPlay];
[moviePlayer play];
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
if(_globle==1)
{
[self replayAudio];
}
else if(_globle==2)
{
DataClass *obj=[DataClass getInstance];
obj.soundInfo=[resultArrayFinal objectAtIndex:count++];
if (count==[resultArrayFinal count])
count=0;
[self replayAudio];
}
}
感谢。