Nit*_*hel 5 objective-c push-notification apple-push-notifications ios rich-notifications
我正在处理丰富的通知Notification Content Extension,并且能够加载images并gif成功地喜欢以下屏幕截图:
现在我正在尝试播放视频,我正在按照代码播放它.
- (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, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.VideoPlayerView.layer addSublayer:playerLayer];
[player play];
}
}
Run Code Online (Sandbox Code Playgroud)
在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, 0, self.VideoPlayerView.frame.size.width, self.VideoPlayerView.frame.size.height);
[self.VideoPlayerView.layer addSublayer:playerLayer];
[player play];
}
}
}
Run Code Online (Sandbox Code Playgroud)
视频正在播放。嘘……
| 归档时间: |
|
| 查看次数: |
1892 次 |
| 最近记录: |