现在我正在尝试播放视频,我正在按照代码播放它.
- (voID)dIDReceiveNotification:(UNNotification *)notification { //self.label.text = @"HELLO world";//notification.request.content.body; if(notification.request.content.attachments.count > 0) { UNNotificationAttachment *Attachen = notification.request.content.attachments.firstObject; NSLog(@"====url %@",Attachen.URL); AVAsset *asset = [AVAsset assetWithURL:Attachen.URL]; AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset]; AVPlayer *player = [AVPlayer playerWithPlayerItem:item]; AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player]; playerLayer.contentsGravity = AVLayerVIDeoGravityResizeAspect; player.actionAtItemEnd = AVPlayerActionAtItemEndNone; playerLayer.frame = CGRectMake(0,self.vIEw.frame.size.wIDth,self.vIEw.frame.size.height); [self.VIDeoPlayerVIEw.layer addSublayer:playerLayer]; [player play]; }}
在NSLog中,我也获得了视频的文件URL.但那不会玩.如果任何人有这个解决方案,请帮助.
谢谢.
解决方法 这是我用代码做的非常小的错误.如果我执行如下代码,我们必须检查startAccessingSecurityScopedResource- (voID)dIDReceiveNotification:(UNNotification *)notification { if(notification.request.content.attachments.count > 0) { UNNotificationAttachment *Attachen = notification.request.content.attachments.firstObject; if(Attachen.URL.startAccessingSecurityScopedResource) { NSLog(@"====url %@",Attachen.URL); AVAsset *asset = [AVAsset assetWithURL:Attachen.URL]; AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset]; AVPlayer *player = [AVPlayer playerWithPlayerItem:item]; AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player]; playerLayer.contentsGravity = AVLayerVIDeoGravityResizeAspect; player.actionAtItemEnd = AVPlayerActionAtItemEndNone; playerLayer.frame = CGRectMake(0,self.VIDeoPlayerVIEw.frame.size.wIDth,self.VIDeoPlayerVIEw.frame.size.height); [self.VIDeoPlayerVIEw.layer addSublayer:playerLayer]; [player play]; } }}
视频正在播放. Boooom …
总结以上是内存溢出为你收集整理的ios – 丰富推送通知 – 视频无法在通知内容扩展中播放全部内容,希望文章能够帮你解决ios – 丰富推送通知 – 视频无法在通知内容扩展中播放所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)