4、空间中如何做到播放视频 - ANTVideo

上篇文章介绍了空间UI的布局,本篇我将介绍如何往场景中添加视频。
ANTVideo可支持的播放器:
AVPlayer:
ijkplayer:已经支持硬解码/软解码。做vr视频直播需要用ijkplayer。

// 渲染模型
typedef NS_ENUM(NSInteger, ANTRenderModel) {
    ANTVR_2D,                                   // 2d
    ANTVR_SPHERE,                               // 全景
    ANTVR_STEREO_SPHERE_LEFT_RIGHT,             // 立体全景 - 左右
    ANTVR_STEREO_SPHERE_UP_DOWN,                // 立体全景 - 上下
    ANTVR_PLANE,                                // 平面
    ANTVR_STEREO_PLANE_LEFT_RIGHT,              // 立体平面 - 左右
    ANTVR_STEREO_PLANE_UP_DOWN,                 // 立体平面 - 上下
    ANTVR_FISHSPHERE_HIGH,                      // 960 * 2560
    ANTVR_FISHSPHERE_RETINA_HIGH,               // 1520 * 2688
    ANTVR_FISHSPHERE_MEDIUM,                    // 960 * 1920
    ANTVR_FISHSPHERE_RETINA_MEDIUM,             // 1080 * 1920
}; mode的模式为以上可选。


实例化avplayer视频对象:url为视频地址(可本地或者网络地址)
ANTVideo *video = [[ANTVideo alloc] initAVPlayerVideoWithURL:url VideoMode:mode];


实例化avplayer视频对象:playerItem为AVPlayerItem。
ANTVideo *video = [[ANTVideo alloc] initAVPlayerVideoWithPlayerItem:playerItem VideoMode:mode];


实例化ijkplayer视频对象:url为视频地址(可本地或者网络地址)
ANTVideo *video = [[ANTVideo alloc] initIJKPlayerVideoWithURL:url VideoMode:mode];

切换模式

[self.antVideo changeDisplayMode:ANTVR_FISHSPHERE_MEDIUM];

若使用ijkplayer,ijk的一些参数设置如下:(参数设置具体看github上的ijkplayer)
软/硬解码直接设置:(0/1)

[options setOptionIntValue:1 forKey:@"videotoolbox" ofCategory:kIJKFFOptionCategoryPlayer];
- (void)setupIJKPlayer:(NSURL *)url
{
    if (!self.ijkPlayer)
    {
        [IJKFFMoviePlayerController setLogReport:YES];
        [IJKFFMoviePlayerController setLogLevel:k_IJK_LOG_UNKNOWN];
        [IJKFFMoviePlayerController checkIfFFmpegVersionMatch:YES];
        
        IJKFFOptions *options = [IJKFFOptions optionsByDefault];
        [options setOptionIntValue:IJK_AVDISCARD_DEFAULT forKey:@"skip_frame" ofCategory:kIJKFFOptionCategoryCodec];
        [options setOptionIntValue:IJK_AVDISCARD_DEFAULT forKey:@"skip_loop_filter" ofCategory:kIJKFFOptionCategoryCodec];
        [options setOptionIntValue:1 forKey:@"videotoolbox" ofCategory:kIJKFFOptionCategoryPlayer];
        [options setOptionIntValue:30 forKey:@"max-fps" ofCategory:kIJKFFOptionCategoryPlayer];
        [options setPlayerOptionIntValue:960 * 2 forKey:@"videotoolbox-max-frame-width"];
    
        self.ijkPlayer = [[IJKFFMoviePlayerController alloc] initWithContentURL:url withOptions:options];
        self.ijkPlayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
        self.ijkPlayer.view.frame = [UIScreen mainScreen].bounds;
        self.ijkPlayer.scalingMode = IJKMPMovieScalingModeAspectFit;
        self.ijkPlayer.shouldAutoplay = YES;
        
        [NotificationCenter addObserver:self selector:@selector(moviePlayerFirstVideoFrameRender:) name:IJKMPMoviePlayerFirstVideoFrameRenderedNotification object:self.ijkPlayer];
    }
    
    [self.ijkPlayer prepareToPlay];
    
    [self setupVideoIJKPlayer:self.ijkPlayer];
}

具体使用方法看提供的avplayerdemo和ijkplayerdemo.

你可能感兴趣的:(4、空间中如何做到播放视频 - ANTVideo)