【发布时间】:2017-12-07 11:40:12
【问题描述】:
我们有一个应用程序允许用户将视频和图像上传到服务器。 如果我从 android 上传 mp4 视频,它不会在 ios 设备中播放。 这是我的代码。播放器状态显示 readytoplay 但它没有加载并且没有出现错误。 vieo 在 web 和 android 上运行良好。 这是视频网址:https://justgolive.net/assets/uploads/newrecordings/20919/19777983355a28e15326df6.mp4
NSURL *streamURL = [NSURL URLWithString:_videoUrl];
player = [AVPlayer playerWithURL:streamURL];
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
playerLayer.frame =self.previewView.frame;
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
//CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height/1.2);
[self.previewView.layer addSublayer:playerLayer];
// [self.playerContainer setUserInteractionEnabled:NO]; //to avoid touch events when activity is on
[self.player addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:NULL];
player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[player currentItem]];
【问题讨论】:
-
你调用播放器的播放方法了吗?
-
是的,iad添加[player play];
标签: objective-c avplayer