标签: avplayer

AVPlayer:如何处理网络中断

当使用AVPlayer从网址播放音频时,它将停止播放,例如断开与wifi的连接.

[player play];
Run Code Online (Sandbox Code Playgroud)

不恢复AVPlayer

player.rate // Value is 1.0

player.currentItem.isPlaybackLikelyToKeepUp // Value is YES

player.status // Value is AVPlayerStatusReadyToPlay

player.error // Value is nil
Run Code Online (Sandbox Code Playgroud)

但播放器没有播放任何音频.

如何处理与AVPlayer的断开连接,重新连接AVPlayer并重新开始播放?

objective-c ios avplayer

13
推荐指数
2
解决办法
1万
查看次数

使用AVPlayer播放时如何将音频连接到蓝牙

我正在使用AVPlayer从网址播放音频,但是当iPhone连接到蓝牙设备时它不能通过蓝牙播放,如果连接后如何通过蓝牙播放,我看到SO中的一些帖子,但这些都不是清楚解释.以下是我的代码.

    -(void)playselectedsong{

    AVPlayer *player = [[AVPlayer alloc]initWithURL:[NSURL URLWithString:urlString]];
    self.songPlayer = player;
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(playerItemDidReachEnd:)
                                                 name:AVPlayerItemDidPlayToEndTimeNotification
                                               object:[songPlayer currentItem]];
    [self.songPlayer addObserver:self forKeyPath:@"status" options:0 context:nil];
    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateProgress:) userInfo:nil repeats:YES];

    [self.songPlayer play];

}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {

    if (object == songPlayer && [keyPath isEqualToString:@"status"]) {
        if (songPlayer.status == AVPlayerStatusFailed) {
            NSLog(@"AVPlayer Failed");

        } else if (songPlayer.status == AVPlayerStatusReadyToPlay) {
            NSLog(@"AVPlayerStatusReadyToPlay");


        } else if (songPlayer.status == AVPlayerItemStatusUnknown) {
            NSLog(@"AVPlayer Unknown");

        }
    }
}

- (void)playerItemDidReachEnd:(NSNotification *)notification { …
Run Code Online (Sandbox Code Playgroud)

iphone bluetooth avaudioplayer ios avplayer

13
推荐指数
2
解决办法
4822
查看次数

iOS:AVPlayerViewController在纵向应用程序中启用全屏旋转

我有一个UIViewcontroller,它包含一个带AVPlayer的AVPlayerViewController.我想为AVPlayerViewController启用旋转(当视频在全屏时)并禁用UIViewController的任何旋转.如何在我的应用中为视频(全屏)启用旋转?

fullscreen avfoundation ios avplayer avplayerviewcontroller

13
推荐指数
1
解决办法
5615
查看次数

MPNowPlayingInfoCenter nowPlayingInfo通过AirPlay忽略AVPlayer音频

我已经使用AVPlayer实现了音频播放,播放了一个远程mp3网址.

我想使用该MPNowPlayingInfoCenter nowPlayingInfo方法显示有关当前播放音频的信息.

当我锁定屏幕时,我确实看到了我设置的图像和标题,所以我知道这种方法是以某种方式注册信息,但是当我将AirPlay切换到AppleTV时,显示器看起来像一个通用的视频输出,底部的进度条,但正确显示已用时间和持续时间.

如果我设置相同nowPlayingInfo,但然后使用AudioQueue启动一些音频,那么它会在屏幕的一半上正确显示图像(它看起来就像播放iPod /音乐应用程序的播客一样).

这仅仅是使用AVPlayer对AirPlay支持音频的限制,还是有一些方法可以让它正确显示图像和信息?

audio ios avplayer airplay mpnowplayinginfocenter

12
推荐指数
2
解决办法
3736
查看次数

保存AVPlayer的缓冲区数据

我在我的应用程序中使用AVPlayer从我的服务器播放音频.现在我想要它完全缓冲音频然后我可以将该数据保存在应用程序中以便稍后播放.所以任何指导或帮助我如何访问缓冲区数据并保存以供以后使用

iphone cocoa-touch ios avplayer

12
推荐指数
2
解决办法
1万
查看次数

如何在AVPlayer实际开始播放时注册(来自外部源)

当玩家开始播放外部视频(通过互联网)使用时,我在注册时遇到了一些麻烦AVPlayer.在提出解决方案之前,请先阅读问题.我像这样初始化播放器:

player = [[AVPlayer alloc] initWithURL:[[NSURL alloc] initWithString:@"http://example.com/video.mp4"]];
playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
[playerLayer setFrame:[videoView bounds]];
[videoView.layer addSublayer:playerLayer];
Run Code Online (Sandbox Code Playgroud)

这会将播放器正确添加到视图中.我添加了以下两行代码来跟踪播放器何时准备好以及状态/速率是多少;

[player addObserver:self forKeyPath:@"rate" options:0 context:nil];
[player addObserver:self forKeyPath:@"status" options:0 context:nil];
Run Code Online (Sandbox Code Playgroud)

- (void)observeValueForKeyPath:....当某些内容随着状态或速率发生变化时,这两行将调用该方法AVPlayer.

到目前为止它看起来像这样:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context 
{
    //To print out if it is 'rate' or 'status' that has changed:
    NSLog(@"Changed: %@", keyPath); 

    if ([keyPath isEqualToString:@"rate"]) //If rate has changed:
    { 
        if ([player rate] != 0) //If it started playing
        {
            NSLog(@"Total time: …
Run Code Online (Sandbox Code Playgroud)

cocoa-touch objective-c avfoundation ios avplayer

12
推荐指数
2
解决办法
3909
查看次数

AVPlayer删除背景音乐

我一直在使用giffycat在我的应用程序中解码,存储和播放GIF.我正在制作它,以便它可以轻松地在UICollectionView的单元格中加载一个gif,所以我决定让每个gif模型都拥有自己的AVPlayer.我注意到,只需创建一个AVPlayer,如下所示,来自其他应用程序的音频就会被杀死!对用户和创作者都很烦人!

// Create an AVURLAsset with an NSURL containing the path to the video
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:_mp4] options:nil];
// Create an AVPlayerItem using the asset
AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset];
_player = [AVPlayer playerWithPlayerItem:item]; //if this line is commented out, I hear audio, else audio from Spotify is quickly killed...
Run Code Online (Sandbox Code Playgroud)

由于这些视频只是GIF,我想知道是否有某种方法可以取消分配音频会话.我对此并不了解.ples帮忙!

ios avplayer

12
推荐指数
1
解决办法
2442
查看次数

避免视频开始和结束时的模糊(即使在使用setPreferredVideoStabilizationMode:AVCaptureVideoStabilizationModeAuto之后)?

我们在iOS上捕捉视频的同时使用setPreferredVideoStabilizationMode:AVCaptureVideoStabilizationModeAuto,但视频仍然有时出来模糊在开始和结束时(中间细,虽然),因为我们抢第一帧作为静止图像(以这是很成问题无需切换相机模式即可启用视频和照片功能).

将设备平放在桌面上可以消除所有模糊现象,因此整个视频都非常清晰.这表明它与视频稳定有关,但还有其他属性可以设置吗?

锁定焦点模式是否重要?

还有其他疑难解答吗?

以下是PBJVision的视频捕捉功能,我们使用它:

- (void)startVideoCapture
{
    if (![self _canSessionCaptureWithOutput:_currentOutput] || _cameraMode != PBJCameraModeVideo) {
        [self _failVideoCaptureWithErrorCode:PBJVisionErrorSessionFailed];
        DLog(@"session is not setup properly for capture");
        return;
    }

    DLog(@"starting video capture");

    [self _enqueueBlockOnCaptureVideoQueue:^{

        if (_flags.recording || _flags.paused)
            return;

        NSString *guid = [[NSUUID new] UUIDString];
        NSString *outputFile = [NSString stringWithFormat:@"video_%@.mp4", guid];

        if ([_delegate respondsToSelector:@selector(vision:willStartVideoCaptureToFile:)]) {
            outputFile = [_delegate vision:self willStartVideoCaptureToFile:outputFile];

            if (!outputFile) {
                [self _failVideoCaptureWithErrorCode:PBJVisionErrorBadOutputFile];
                return;
            }
        }

        NSString *outputDirectory = (_captureDirectory == nil ? NSTemporaryDirectory() : _captureDirectory); …
Run Code Online (Sandbox Code Playgroud)

video ios avcapturesession avplayer pbjvision

12
推荐指数
1
解决办法
1068
查看次数

如何使用UICollectionview播放Facebook风格的视频

我正在尝试UICollectionview使用ZOWVideoPlayer在Cell中播放视频.视频播放效果很好,但目前我的收藏视频正在播放所有可见视频.我想只播放一个完全可见的视频.这意味着当前视频未通过滚动处理裁剪(像素不在屏幕外,但完全可见).

我还添加了代码来检查scrollview委托方法中的完整可见单元格,但随后我的collectionview卡住了1或2秒然后移动,所以请帮助我.

请先阅读问题,然后进行投票.

这是检查可见单元格的代码

- (void)checkVisibilityOfCell:(CustomCell *)cell inScrollView:(UIScrollView *)aScrollView {
    @try {
        CGRect cellRect = [aScrollView convertRect:cell.frame toView:aScrollView.superview];
        if (cell.videoPlayer) {
            if (CGRectContainsRect(aScrollView.frame, cellRect)){
                //Play Video
            }
            else{
                //Pause Video
            }
        }
    } @catch (NSException *exception) {

    } @finally {

    }
}
Run Code Online (Sandbox Code Playgroud)

video objective-c ios avplayer swift

12
推荐指数
1
解决办法
1398
查看次数

倒带时AVPlayer currentTime错误

我回放音频文件时有AVPlayer,然后当前时间比总文件持续时间长.谁知道问题是什么,为什么目前的时间错了?

@objc func updateProgressBar(){
    guard let value = AppDelegate.avPlayer.currentItem?.currentTime().seconds else { return }
    let time = Func.getHoursMinutesSecondsFrom(seconds: value)
    DispatchQueue.main.async {
        self.startTime.text = time.fullTime
    }
}


func durationAudio(){
    // ??????????? ????? ??????????
    guard let duration = AppDelegate.avPlayer.currentItem?.asset.duration else { return }
    let time = Func.getHoursMinutesSecondsFrom(seconds: CMTimeGetSeconds(duration))
    DispatchQueue.main.async {
        self.endTime.text = time.fullTime
    }
}
Run Code Online (Sandbox Code Playgroud)

转换为小时,分钟,秒

static func getHoursMinutesSecondsFrom(seconds: Double) -> (hours: Int, minutes: Int, seconds: Int, fullTime:String) {
    let secs = Int(seconds)
    let hours = secs / 3600
    let minutes = (secs …
Run Code Online (Sandbox Code Playgroud)

avplayer swift

12
推荐指数
0
解决办法
156
查看次数