小编mvi*_*hnu的帖子

知道AVPlayer对象何时可以播放

我正在尝试播放一个MP3传递给UIView前一个文件的文件UIView(存储在一个NSURL *fileURL变量中).

我正在初始化一个AVPlayer:

player = [AVPlayer playerWithURL:fileURL];

NSLog(@"Player created:%d",player.status);
Run Code Online (Sandbox Code Playgroud)

我想的NSLog印刷品Player created:0,意味着它尚未准备好播放.

当我点击播放时UIButton,我运行的代码是:

-(IBAction)playButtonClicked
{
    NSLog(@"Clicked Play. MP3:%@",[fileURL absoluteString]);

    if(([player status] == AVPlayerStatusReadyToPlay) && !isPlaying)
//  if(!isPlaying)
    {
        [player play];
        NSLog(@"Playing:%@ with %d",[fileURL absoluteString], player.status);
        isPlaying = YES;
    }
    else if(isPlaying)
    {

        [player pause];
        NSLog(@"Pausing:%@",[fileURL absoluteString]);
        isPlaying = NO;
    }
    else {
        NSLog(@"Error in player??");
    }

}
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我总是进入Error in player??控制台.然而,如果我用一个简单的...... 替换if检查是否 …

iphone avfoundation audio-streaming avplayer

71
推荐指数
8
解决办法
7万
查看次数

标签 统计

audio-streaming ×1

avfoundation ×1

avplayer ×1

iphone ×1