Tag: avplayer

使用Hanekecaching,然后用AVPlayer播放MP4文件

我正在寻找一些帮助来解决看起来像一个简单的问题,但我似乎无法弄清楚。 我使用Cocoapods的Hanekecaching来自URL(在我的服务器上)的MP4文件,然后使用AVPlayer播放caching的版本。 我在UICOllectionViewCell中设置了一个AVPreviewLayer并运行这个代码。 问题是播放器最初不会播放video,但将来会再播放(在我回滚到uicollectionview中的那个单元格之后) let getUrl = NSURL(string: location) cache.fetch(URL: getUrl!).onSuccess { (data) in // Hacky way of getting cache URL from Haneke let basePath = DiskCache.basePath().stringByAppendingPathComponent("shared-data/original/") let path = DiskCache(path: basePath, capacity: UINT64_MAX).pathForKey(getUrl!.absoluteString) let fileURL = NSURL(fileURLWithPath: path) self.player = AVPlayer(URL: fileURL) let playerLayer = AVPlayerLayer(player: self.player) playerLayer.frame = self.view.bounds cell.videoView.layer.addSublayer(playerLayer) print("Playing video") self.player.play() […]

如何从下一首歌曲开始,或者在播放AVPlayer的过程中认出一首歌曲已经完成?

如何用AVPlayer立即启动下一首歌曲? 我有从MPMediaItemCollection iPod库中select歌曲的集合。 现在我怎样才能使用AVPlayer的歌曲列表一一播放?

当ViewController加载时,UISlider的AVPlayer currentTime更新

我正在播放AVPlayer歌曲。 我为我的媒体播放器和初始化创build了一个独立的视图控制器,并且我为播放器使用的所有方法(播放,暂停,重复,随机播放)都在同一个视图控制器中。 我更新像这样的滑块 [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(sliderUpdate:) userInfo:nil repeats:YES];` – (void) sliderUpdate:(id) sender{ int currentTime = (int)((song.player.currentTime.value)/song.player.currentTime.timescale); slider.value=currentTime; NSLog(@"%i",currentTime); song.currentTime=currentTime; int currentPoint=(int)((song.player.currentTime.value)/song.player.currentTime.timescale); int pointMins=(int)(currentPoint/60); int pointSec=(int)(currentPoint%60); NSString *strMinlabel=[NSString stringWithFormat:@"%02d:%02d",pointMins,pointSec]; lblSlidermin.text=strMinlabel; song.strslidermin=strMinlabel; } 一旦我走出视图控制器,当再来,歌曲播放,但问题是滑块不更新。 所以我创build了一个单独的类来分配当前播放的歌曲细节。 同样在滑块内部更新我为singleton类variables赋值playerCurrentTime(slidercurrent值)。 而我的viewdidload方法我这样分配 if (song.isPlaying==NO) { [self prePlaySong]; }else{ lblAlbum.text=song.currentAlbum; lblArtist.text=song.currentArtist; lblSong.text=song.currentSong; slider.value=song.currentTime; slider.maximumValue=song.sliderMax; slider.minimumValue=song.sliderMin; imgSong.image=song.songImage; [btnMiddle setBackgroundImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal]; } 但滑块没有得到更新。 […]

如何对AVPlayer的播放和暂停操作执行一些操作?

我用AVPlayer在我的swift应用程序上播放video。 我想在video的中间放置一个播放button(自定义button)。 我知道如何玩点击button暂停video。 当video从默认button播放/暂停时,我找不到如何显示/隐藏自定义button? video播放/暂停时是否有任何听众或某些事件触发? 我也想从默认控制中隐藏“audio和字幕”图标。

是否可以设置AVPlayer允许设备在video播放过程中进入睡眠状态?

我正在研究一个应用程序,涉及使用AVPlayer在一个接口的背景下有一个video。 我们发现,虽然video播放,应用程序将永远不会睡觉。 有没有办法告诉AVPlayer允许应用程序进入睡眠不pipe?

AvPlayer当应用程序变为背景时暂停并播放问题

它的工作正常,如果应用程序只是变得不活跃/活跃(当一些警报来了,或通过双击主页button) AVPlayer *播放器; – (void)applicationWillResignActive:(UIApplication *)application { [player pause]; } – (void)applicationDidBecomeActive:(UIApplication *)application { [player play]; } 如果应用程序转到后台(通过点击homebutton)并返回,则不会从暂停位置播放,而不是从不同的位置(有时从开始,有时从中间)播放。 可能是什么问题?

当创build了太多的AVPlayer实例时,AVPlayerItemStatusFailed错误

我正在创build一个iOS应用程序,该应用程序创build用户池提交的所有video的供稿,使用户能够浏览和查看其他人创build的video。 正如您所想象的,我需要能够支持Feed中的任意数量的video。 目前,我正在为每个video创build和保留一个AVPlayer实例,如下所示: //inside the init method of a UIView //create the AVPlayer and store it in a strong property NSString * urlString = @"aRemoteURL.mov"; NSURL * movURL = [NSURL URLWithString:urlString]; _videoPlayer = [[AVPlayer alloc]initWithURL:movURL]; //register callbacks for handling buffering [_videoPlayer.currentItem addObserver:self forKeyPath:@"playbackBufferEmpty" options:NSKeyValueObservingOptionNew context:nil]; [_videoPlayer.currentItem addObserver:self forKeyPath:@"playbackLikelyToKeepUp" options:NSKeyValueObservingOptionNew context:nil]; //add the AVPlayerLayer to the […]

如何从iOS的ALAsset获取video的缩略图图像?

我想从video中获取每帧的缩略图图像,然后将这些图像保存在可变数组图像中。 我想用这个图像作为animation播放。 NSURL* assetURL = [self.asset valueForProperty:ALAssetPropertyAssetURL]; NSDictionary* assetOptions = nil; AVAsset* myAsset = [[AVURLAsset alloc] initWithURL:assetURL options:assetOptions]; self.imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:myAsset]; int duration = CMTimeGetSeconds([myAsset duration]); for(int i = 0; i<duration; i++) { CGImageRef imgRef = [self.imageGenerator copyCGImageAtTime:CMTimeMake(i, duration) actualTime:NULL error:nil]; UIImage* thumbnail = [[UIImage alloc] initWithCGImage:imgRef scale:UIViewContentModeScaleAspectFit orientation:UIImageOrientationUp]; [thumbnailImages addObject:thumbnail]; } 我使用上面的代码来获取缩略图图像,但问题是如果有一个2秒的video,我只得到2个缩略图,但我想要20个缩略图(10个缩略图每秒)。 那么,如何使用CMTimeMake来获取每一秒的缩略图

如何在iOS中播放没有文件扩展名的video?

我需要在这个url播放video: http : //ep-lin-upload.s3.amazonaws.com/vupl_lin/F64/CDF/F64CDF3B0348471E95C244DE2DDDD3F3 video的MIMEtypes是:video / mp4 NSURL *adURL = [NSURL URLWithString:@"http://ep-lin-upload.s3.amazonaws.com/vupl_lin/F64/CDF/F64CDF3B0348471E95C244DE2DDDD3F3"]; AVPlayer *player = [AVPlayer playerWithURL:adURL]; 此代码适用于文件扩展名的url。 但是,如果没有文件扩展名,AVPlayer不能识别MIMEtypes。 我怎样才能解决这个问题?

Progressive Video在iOS上下载

我正在尝试在iOS应用程序中通过AVPlayer播放video的渐进式下载 。 我已经实现了一个可以下载文件到iPad的下载器模块。 但是,我发现我无法播放仍在写入的文件 所以,据我所知,我唯一的解决办法是通过下载一个文件“块”的列表,然后继续播放每个文件,因为他们准备好了(即:下载),可能使用HLS search我遇到了这个通过hls实现渐进式下载的问题,除此以外 ,我找不到其他方法 不过,我不断遇到search结果,说如何configurationWeb服务器利用iOS支持HTTP渐进式下载,但没有提到如何从iOS端做到这一点 那么,有没有人有任何想法和/或经验呢? 编辑:我也发现有可能是这样做的其他方式(即:stream,然后写stream媒体数据到磁盘),这是由这个问题,但仍然无法得到它的工作,因为它似乎不工作非本地资产!