【发布时间】: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