Tag: avplayer

AVPlayerstream媒体由于缺口而在后台停止

我试图实现无缝播放,因为当应用程序处于后台模式时,iOS会将我的AVPlayer闲置。 在回答之前,是的,我已经修改了plist,audio会话设置正确,一切都很好,但是我相信,我的问题本质上是不同的。 所以,起初我在我的课上有一个方法来初始化一个新的AVPlayer每当轨道URL改变,它运作良好,但在后台不是很多,我虽然每次创build一个全新的AVPlayer实例将无法正常工作,所以我切换到其他一些范例,比如replaceCurrentItemWithPlayerItem保持AVPlayer实例活着,甚至是AVQueuePlayer 。 我面对的问题是,在iOS 6上,audio停止的时刻,因为一个轨道完成,另一个还需要加载,iPhone冻结在后台我的应用程序。 如果我再次在前台获得我的应用程序,播放恢复正常。 由于我没有连续的stream,而是单独的URL来AVPlayerQueuestream,我虽然有关使用AVPlayerQueue和insertItem:next / advanceToNextItem策略,试图不让任何最小的audio中断冻结在后台的应用程序。 但问题仍然存在,因为我不得不在需求队列中添加新的轨道,并且缓冲iOS的时间已经认为我的应用程序值得停下来。 所以我需要在应用程序的生命周期适当的时间insertItem 。 那时我正试图听取这个KVO通知: [self.player.currentItem addObserver:self forKeyPath:@"playbackBufferFull" options:0 context:MyPlayerItemContext]; 但它永远不会被调用。 我们的想法是跟踪currentItem上的缓冲区,并在播放列表中追加下一个缓冲区,以便AVQueuePlayer 可以尝试预缓冲它。 由于playbackBufferFull永远不会被调用,另一个想法是试图抓取当前的时间/持续时间,计算90%的回放可能在哪里,并在适当的时间触发事件来开始缓冲下一个轨道。 这听起来很糟糕,因为对象的持续时间属性会根据渐进式传入数据而改变吗? 我还能采取哪些其他策略? 谢谢。

如何replaceMPMoviePlayer通知?

在iOS 9 MPMoviePlayer和他的所有组件都被弃用。 我们使用MPMoviePlayerController通知,如MPMoviePlayerLoadStateDidChangeNotification, MPMovieDurationAvailableNotification, MPMoviePlayerPlaybackStateDidChangeNotification, MPMoviePlayerReadyForDisplayDidChangeNotification ,来跟踪video服务质量。 但现在用AVPlayerViewController我无法find正确的替代这些通知。 我现在如何replace这些通知?

AVCaptureMovieFileOutput后用AVPlayer播放video

我用AVFoundation创build了类似于snapchat的自定义相机。 图片方面的作品:拍照,我显示图片。 现在我正在试着拍一个video并显示video。 我已经捕获了一个成功的video文件,经过testing并与MPMoviePlayer一起工作,但无法在AVPlayer上播放。 – (void)takeVideoAction:(id)sender { NSString *outputPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"output.mp4"]; NSFileManager *manager = [[NSFileManager alloc] init]; if ([manager fileExistsAtPath:outputPath]){ [manager removeItemAtPath:outputPath error:nil]; } [movieFileOutput startRecordingToOutputFileURL:[NSURL fileURLWithPath:outputPath] recordingDelegate:self]; } – (void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error{ AVURLAsset *asset = [AVURLAsset URLAssetWithURL:outputFileURL options:nil]; [asset loadValuesAsynchronouslyForKeys:@[@"tracks"] completionHandler:^{ dispatch_async(dispatch_get_main_queue(), ^{ NSError *error = nil; if([asset […]

Swift AVPlayerViewController添加AirPlay

我试图启用AirPlay与我的AVPlayerViewController 。 在文件中: https://developer.apple.com/reference/avkit/avplayerviewcontroller 它指出 AVPlayerViewController automatically supports AirPlay, but you need to perform some project and audio session configuration before it can be enabled in your application. 在Capabilities选项卡下,我确实启用了audio,AirPlay和图片中的背景模式。 我已经创build了AVPlayerViewController ,如下所示: // Create the view controller and player let moviePlayerViewController: AVPlayerViewController = AVPlayerViewController() let moviePlayer = AVPlayer(url: videoUrl!) moviePlayer.allowsExternalPlayback = true moviePlayer.usesExternalPlaybackWhileExternalScreenIsActive = true // […]

无法通过iOS中的AVPlayer从文档目录中播放音乐?

我正在使用MediaPickerController挑选音乐文件。当我从拾音器中select音乐文件后,我将文件保存到文档目录。 以下是select和保存到文档目录的代码 //code to click on music button – (IBAction)addMusic:(id)sender { MPMediaPickerController *soundPicker=[[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic]; soundPicker.delegate=self; soundPicker.allowsPickingMultipleItems=NO; [self presentViewController:soundPicker animated:YES completion:nil]; } – (void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection { NSLog(@"music files delegate called"); MPMediaItem *item = [[mediaItemCollection items] objectAtIndex:0]; [self uploadMusicFile:item]; [self dismissViewControllerAnimated:YES completion:nil]; } – (void) uploadMusicFile:(MPMediaItem *)song { NSURL *url = [song valueForProperty: […]

AVPlayer – 在播放时切换stream的质量

我正在使用AVPlayer播放YouTubevideo,对于每个YouTubevideoID我检索几个不同品质的streamurl。 我想根据networking状态播放特定的stream媒体质量。 例如,如果用户在3G上,我想播放质量最低的URL,但是如果用户移动到WiFi,我想无缝切换到更好的质量stream。 这不是什么新鲜事,YouTube正在他们的应用程序和其他许多应用程序中这样做。 所以我想知道用AVPlayer进行这种切换的最佳方法是什么,我不希望用户注意到切换,而不会暂停video播放或缓冲。 任何build议? 我不确定在YouTube服务器上是否支持这种function,或者是否需要在客户端执行此function。

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]; } […]

如何检测AVPlayerItem何时完成播放?

我一直在查看AVPlayerItem和AVPlayer文档,并且似乎没有任何callback,当项目完成播放。 我希望能有一些委托callback,我们可以利用或AVPlayerActionAtItemEnd将提供一个自定义的行动,我们写。 我怎样才能找出一种方法来检测什么时候AVPlayer已经完成播放项目?

为什么AVPlayer在后台不能继续播放下一首歌?

我一直使用AVPlayer从远程来源播放音乐。 我得到的URL,使用一个创build一个AVPlayerItem,然后我与AVPlayer的实例关联。 我将一个观察者添加到与播放器关联的项目中,以观察项目何时完成播放( AVPlayerItemDidPlayToEndTimeNotification )。 当观察者在项目结束时通知我时,然后创build一个新的AVPlayerItem并重新执行。 这在iOS 9.2的前台和后台运行良好。 问题:由于我已经更新到iOS 9.3,这在后台不起作用。 这是相关的代码: var portionToBurffer = Double() var player = AVPlayer() func prepareAudioPlayer(songNSURL: NSURL, portionOfSongToBuffer: Double){ self.portionToBuffer = portionOfSongToBuffer //create AVPlayerItem let createdItem = AVPlayerItem(URL: songNSURL) //Associate createdItem with AVPlayer player = AVPlayer(playerItem: createdItem) //Add item end observer NSNotificationCenter.defaultCenter().addObserver(self, selector: "playerItemDidReachEnd:", name: AVPlayerItemDidPlayToEndTimeNotification, object: player.currentItem) //Use KVO […]

在AVPlayer中获得averagePowerForChannel

我怎样才能得到在AVPlayer averagePowerForChannel为了使我的音乐应用程序的audio可视化! 我已经做了可视化部分,但我卡在它的引擎(实时音量通道)。 我知道通过使用AVAudioPlayer它可以很容易地使用.meteringEnabled属性,但由于一些已知的原因AVPlayer是必须在我的应用程序! 我真的想用AVAudioPlayer除了AVPlayer获得所需的结果,但它听起来有点混乱的解决方法,如何影响性能和稳定性? 提前致谢