AVPlayer播放不超过一次 [英] AVPlayer doesn't play more than one time

查看:80
本文介绍了AVPlayer播放不超过一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在通过AVPlayerItem&播放音频时遇到一些奇怪的问题AVPlayer.

I have some strange problem with playing audio through AVPlayerItem & AVPlayer.

我有录音机和iPod项目选择器,它们中的流正在通过这样的代码:

I have recorder and iPod item picker, stream from both of them are going through code like this:

  AVAudioSession *audioSession = [AVAudioSession sharedInstance];
  [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
  [audioSession setActive:YES error:nil];

  _playerItem = [[AVPlayerItem alloc] initWithURL:_soundFileURL];
  _player = [[AVPlayer alloc] initWithPlayerItem:_playerItem];
  [_player play];

一切正常,除了一件事,我不能再播放此视频流第二次或更长时间.它只是停止了,停止后没有声音.有人可以提供建议吗,可能是什么问题?

Everything is actually ok, except one thing, I can't play this stream second or more time. It's just stopped, and no sounds are found after stopping. Does anybody can help with an advice, what the problem could be?

推荐答案

您必须使用prepareToPlay并将ACClayer设置回流的开头,并将currentPlaybackTime设置为0.

You have to set the AVPlayer back to beginning of the stream using prepareToPlay and setting the currentPlaybackTime to 0.

self.avPlayer.currentPlaybackTime = 0;
[self.avPlayer prepareToPlay];

这篇关于AVPlayer播放不超过一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆