Alf*_*ien 5 objective-c avfoundation ios
我正在尝试从URL播放流,但这是一个问题.ObserveValueForKeyPath:ofObject:change:context只是不执行.据我了解,这不取决于streamURL,它是否正确.它必须从AVPlayerItemStatusUnknown将状态更改为AVPlayerItemStatusReadyToPlay或AVPlayerItemStatusFailed.但是,我在浏览器中检查了该URL,它运行正常.所以有什么问题?我观看了WWDC视频,它说,如果你有音频流,请在 AVAsset 之前使用AVPLayerItem.
这是我的代码:
- (void) prepare
{
NSURL * trackStreamURL = [NSURL URLWithString:streamURL];
NSLog(@"STREAM URL: %@",trackStreamURL);
_playerItem = [AVPlayerItem playerItemWithURL:trackStreamURL];
[_playerItem addObserver:self forKeyPath:@"status" options:0 context:nil];
}
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
NSLog(@"KEY PATH : %@", keyPath);
NSLog(@"CHANGE : %@", change);
}
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我一直在观察status 属性,AVPlayer而不是AVPlayerItem因为你需要一个玩家来玩玩家物品.事实上,我甚至从未查看过播放器项的状态属性.
玩家项目的状态可能永远不会改变,因为没有玩家准备好玩它.因此,使用玩家项目创建一个玩家并观察玩家的状态(或者可能,仍然是玩家项目的状态).
AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2842 次 |
| 最近记录: |