【问题标题】:MP3 playback and stop issue?MP3播放和停止问题?
【发布时间】:2010-02-13 22:26:56
【问题描述】:

在我退出视图并尝试返回之前,此代码运行良好。如果我这样做,停止按钮将不再起作用。离开视图后如何让它仍然工作?

-(IBAction)musiconButtonClicked:(id)sender{

    NSString *path = [[NSBundle mainBundle] pathForResource:@"NextRevIt" ofType:@"mp3"];
    self.audioPlayer = [[AVAudioPlayer alloc ] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    [audioPlayer play];


}

-(IBAction)musicoffButtonClicked:(id)sender{

    [audioPlayer stop];

}

【问题讨论】:

    标签: ios objective-c mp3 avaudioplayer playback


    【解决方案1】:

    您需要在完成后释放音频播放器。

    您还应该在代码中在 play 之前使用 [audioPlayer prepareToPlay];

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多