Tag: avplayeritem

AVPlayer在线模式下停止播放AESencryption离线HLSvideo

我写了一个代码来下载HLSvideo并以离线模式播放。 此代码适用于编码的video。 现在我有一个AESencryption的video,我们正在为它定制encryption密钥。 下载AESencryption的HLSvideo后,我使用下面给出的代码来提供解密video的密钥。 – (BOOL)resourceLoader:(AVAssetResourceLoader *)resourceLoader shouldWaitForLoadingOfRequestedResource:(AVAssetResourceLoadingRequest *)loadingRequest { NSString *scheme = loadingRequest.request.URL.scheme; if ([scheme isEqualToString:@"ckey"]) { NSString *request = loadingRequest.request.URL.host; NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:request]; if (data) { [loadingRequest.dataRequest respondWithData:data]; [loadingRequest finishLoading]; } else { // Data loading fail } } return NO; } 我截获一个密钥的请求,并传递存储在UserDefaults中的密钥进行解密。 当我的设备的wifi或数据连接closures时,使用自定义密钥的AESencryptionHLSvideo播放效果良好。 如果我在启用设备的wifi或数据连接时开始播放此video,或者在播放video时启用设备的wifi或数据连接, video立即停止播放,没有任何错误,从不再播放。 我检查了playerItem的accessLog和errorLog,但没有发现任何有用的东西。 在下载HLS内容后提供自定义URL密钥我正在更新.m3u8文件的内容 URI = […]

iOS中的AVPlayerViewController播放/暂停问题

我正在开发iOS应用程序。 这个应用程序基于新闻媒体。 我正在播放突出显示的新闻的小video。 我正面临AVPlayerViewController的陌生人问题。 当我播放video一切都很好。 当我离线时,缓冲区video播放完毕播放缓冲区video后,video停止,但progress bar(Slider)连续处于播放状态,video停止播放。 要获得更多的通关请看这个GIF图像: 请访问此链接了解连击。 这是我的玩家代码。 class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. self.playVideo() } func playVideo(){ let videoURL = NSURL(string: "http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8") let player = AVPlayer(URL: videoURL!) let playerController = AVPlayerViewController() playerController.player = player self.addChildViewController(playerController) self.view.addSubview(playerController.view) […]

Swift AVPlayerItem完成后closures

我对Swift和iOS开发非常陌生,所以请原谅我的无知。 我试图在播放完video后自动closuresAVPlayer。 我想附加“playerDidFinishPlaying”侦听器来接收通知,但一旦我有了它,我找不到方法/事件closures控制器。 我正在寻找模仿点击“完成”button的动作。 这是一小段代码。 希望这是足够的信息。 如果没有,我可以提供进一步的信息 let destination = segue.destinationViewController as! AVPlayerViewController let url = NSURL(string: "video url") destination.player = AVPlayer(URL: url!) destination.player?.play() 我已经添加了以下通知,但是一旦拥有了,我不知道该如何处理它… NSNotificationCenter.defaultCenter().addObserver(self, selector: "playerDidFinishPlaying:", name: AVPlayerItemDidPlayToEndTimeNotification, object: destination.player!.currentItem) func playerDidFinishPlaying(note:NSNotification){ print("finished") // close window/controller } 最后,我知道我需要删除观察者,但我不确定何时何地这样做。 任何帮助是极大的赞赏。

iOS8中的AVPlayerItem addobserver问题

您好我正在使用AVPlayer在我的UITableViewCells上播放video,它在iOS 7上工作正常,但在iOS8中它崩溃与以下错误。 'An instance 0x7c01b000 of class AVPlayerItem was deallocated while key value observers were still registered with it. 这是我的代码 – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ……… ……… if(cell.videoPlayer!= nil && cell.videoPlayer.currentItem != nil) { [cell.videoItem removeObserver:self forKeyPath:@"playbackBufferEmpty" context:nil]; [cell.videoItem removeObserver:self forKeyPath:@"playbackLikelyToKeepUp" context:nil]; } cell.videoPlayer = [AVPlayer playerWithPlayerItem:cell.videoItem]; cell.avLayer = [AVPlayerLayer playerLayerWithPlayer:cell.videoPlayer]; cell.videoPlayer.actionAtItemEnd = […]

AVPlayer失败,AVPlayerItemStatusFailed(OSStatus错误-12983)

有时,AVPlayer失败, AVPlayerItemStatusFailed失败,AVPlayer继续失败, AVPlayerItemStatusFailed 。 我试图清除AVPlayer实例并创build一个新的,但我不能实现AVPlayerItemStatusFailed失败解决。 此外,使用AVPlayer实例removingFromSuperview UIView并使用AVPlayer初始化新项目并不能解决问题。 所以我想,AVPlayer不能完全清除。 有没有人build议尝试彻底清除AVPlayer,并使其在失败后工作? 错误日志: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo=0x1a689360 {NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x1a688e70 "The operation couldn't be completed. (OSStatus error -12983.)", NSLocalizedFailureReason=An unknown error occurred (-12983)} UPD。 对于@matt playerItem = [AVPlayerItem playerItemWithURL:[NSURL fileURLWithPath:filePath.path]]; if (!self.avPlayer) { avPlayer = [AVPlayer playerWithPlayerItem:playerItem]; } […]

当创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 […]

AVPlayer被重新分配,而关键价值观察员仍然在注册

我创build一个简单的媒体播放器应用程序。 我的应用程序崩溃时,第一个链接播放,我点击第二个链接在uitableview。 – (void)viewDidLoad { [super viewDidLoad]; arrURL = [NSArray arrayWithObjects: @"http://yp.shoutcast.com/sbin/tunein-station.pls?id=148820", @"http://www.kcrw.com/pls/kcrwmusic.pls",@"http://yp.shoutcast.com/sbin/tunein-station.pls?id=175821",@"http://yp.shoutcast.com/sbin/tunein-station.pls?id=148820",@"http://yp.shoutcast.com/sbin/tunein-station.pls?id=70931",nil]; url = [[NSURL alloc] init]; } – (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [arrURL count]; } – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *MyIdentifier = @"MyIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault […]

从UITableViewCell上的多个AVPlayerItem中添加和删除观察者

我试图做一个表视图播放多个videoAVPlayer和AVPlayerItem ,我需要addObserver到每个AVPlayerItem所以我可以跟踪playbackLikelyToKeepUp属性 我试过和失败的是在设置AVPlayerItem之后添加观察者,并在UITableViewCell的deinit中删除它,但由于单元格永远不会被释放,但得到出列所以这将无法正常工作,我会得到这个错误 An instance 0x14eedebc0 of class AVPlayerItem was deallocated while key value observers were still registered with it. search后,我想出了这个 我不应该在UITableViewCell上添加或删除观察者,但我必须因为播放器项目是在单元格子类 处理观察者的最好方法是在'UITableViewDelegate'方法中 在willDisplayCell添加并在willDisplayCell移除 但即使这不起作用,因为AVPlayerItem需要时间来初始化 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! TableViewCell cell.setUpPLayer() return cell } override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath […]

AVPlayer不会触发playbackBufferEmpty,但不会播放

我使用AVPlayer通过互联网播放audio直播。 如果暂停时间超过1分钟,我喜欢恢复播放。 我打电话player.rate = 1.0恢复。 但是,如果数据stream暂停了1分钟以上,则不能再播放。 在这种情况下,我需要重新创buildAVPlayerItem,使其重新工作。 那么我怎么能抓住这个情况,所以我知道播放没有恢复? 我在player.rate上试过KVO。 它仍然在1.0 。 玩家不玩! 我在currentItem.playbackBufferEmpty上试过KVO。 这不是在这种情况下调用。 currentItem.status不会切换到.Failed 。 它根本没有改变。 在这种情况下AVPlayer似乎什么都不做。 有任何想法吗? 我构build了一个Playground代码来演示这个问题: import UIKit import AVFoundation // keep it running forever so it plays audio import XCPlayground XCPSetExecutionShouldContinueIndefinitely(true) class AVPlayerTest { let player = AVPlayer() let streamurl = NSURL(string: "http://detektor.fm/stream/mp3/musik/")! func startTest() { let item = AVPlayerItem(URL: […]

AVPlayer使用资源加载器委托来拖延大型video文件

我正在使用这种方法来保存AVPlayer的video文件的缓冲区数据。 作为这个问题的答案find保存AVPlayer的缓冲区数据 。 iPhone和iPad – iOS 8.1.3 我做了必要的修改来播放video,除非我尝试播放一个非常长的video(11-12分钟长,大约85mb),video将在连接完成后大约4分钟停止播放。 我得到一个事件为播放缓冲空间和播放器项目停滞通知。 这是代码的要点 viewController.m @property (nonatomic, strong) NSMutableData *videoData; @property (nonatomic, strong) NSURLConnection *connection; @property (nonatomic, strong) AVURLAsset *vidAsset; @property (nonatomic, strong) AVPlayerItem *playerItem; @property (nonatomic, strong) AVPlayerLayer *avlayer; @property (nonatomic, strong) NSHTTPURLResponse *response; @property (nonatomic, strong) NSMutableArray *pendingRequests; /** Startup a Video */ – (void)startVideo { self.vidAsset […]