【问题标题】:Why is AVAudioPlayer not responding?为什么 AVAudioPlayer 没有响应?
【发布时间】:2013-03-13 19:40:57
【问题描述】:

我是 iphone 开发的菜鸟(Xcode 中的第 4 天),我正在尝试实现 AvAudioPlayer 并使用 AwesomeMenu 库对其进行控制。我初始化和播放音频没有问题,但是当我尝试通过很棒的菜单控件暂停或停止音频时,AVAudioPlayer 没有响应。非常感谢任何帮助。

编辑

我能够确定我的方法没有在其中执行条件 if/else 语句。这更莫名其妙。 didSelectIndex 正在触发,但内部的 if 语句不是。我的条件语句编码是否正确?

我的代码:

AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url];
podcastPlayer = [[AVPlayer playerWithPlayerItem:playerItem] retain];
[podcastPlayer play];

//Control for AvAudioPlayer

- (void)AwesomeMenu:(AwesomeMenu *)menu didSelectIndex:(NSInteger)idx{
if (idx==0) {
    if(!podcastPlayer.isPlaying){
        podcastPlayer.play;
    }

}else if(idx==1){
    if(podcastPlayer.isPlaying){
        podcastPlayer.pause;
    }

}else if(idx==2){
    if(podcastPlayer.isPlaying){
        podcastPlayer.stop;
        podcastPlayer.release;

        GSCCAppDelegate *appDelegate = (GSCCAppDelegate *)[[UIApplication sharedApplication] delegate];

        [appDelegate.menu removeFromSuperview];

    }

}else if(idx==3){


}else if(idx==4){

}else if(idx==5){

}

NSLog(@"Select the index : %d",idx);
}

编辑

- (void)AwesomeMenu:(AwesomeMenu *)menu didSelectIndex:(NSInteger)idx{
if (idx==0) {

    NSLog(@"Index 0"); //Doesn't work

}else if(idx==1){

    NSLog(@"Index 1"); //Doesn't work

}

}

NSLog(@"Select the index : %d",idx); //<--This Works.

}

【问题讨论】:

  • 是 didSelectIndex 触发了吗?
  • 是的,它正在返回适当的索引。
  • if(!podcastPlayer.isPlaying) 条件呢?单击索引0时是否返回true?
  • 不,它没有返回值。在这个方法中根本看不到 podcastPlayer 变量
  • 哦..我明白了..做一件事。将 AVPlayerItem *playerItem 声明为属性并合成它。不要声明为本地人。

标签: iphone audio if-statement avaudioplayer audio-streaming


【解决方案1】:

AVPlayerItem *playerItem 声明为propertysynthesis

不要声明为本地人

【讨论】:

  • 请。检查我的编辑。 AvplayerItem 不是问题,我的 if 语句不起作用。
  • 能否将示例代码发送至 ramshadram90@gmail.com ?
猜你喜欢
  • 2010-11-14
  • 1970-01-01
  • 2020-10-16
  • 2021-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-06
相关资源
最近更新 更多