美文网首页VR智库
VR---得图SDK VR视频简单播放

VR---得图SDK VR视频简单播放

作者: 安处幽篁兮 | 来源:发表于2016-12-10 15:24 被阅读0次

    由于是得图F4的设备,所以首选得图,最后是不是,不告诉你


    得图iOS SDK集成参看得图开发者中心:http://developer.detu.com/home/page/show?page_id=41

    需求:全屏重复播放本地全景小视频

    实现效果不好演示,得图只支持真机测试

    具体实现如下:

    <small>注明:只是简单实现,官方demo涵盖了各种类型播放,所以这里抽离出播放视频来,且将其前缀去掉了(不地道😉),但由于与PanoPlayer冲突,所以随便加了个FP前缀。</small>

    VRController.m 
    // 遵守<PanoPlayDelegate>
    // MARK: VR
    @property (nonatomic,strong) FPPanoPlayer *panoplayer; // 播放器承载View
    @property (nonatomic,strong) PicOrMovItem *item; // 播放选项
    @property (nonatomic, assign) PanoVideoPluginStatus playMovStatus; // 播放状态
    
    

    懒加载设置选项

    #pragma mark - getters
    
    - (FPPanoPlayer *)panoplayer{
        if (nil == _panoplayer) {
            FPPanoPlayer *panoplayer = [[FPPanoPlayer alloc] init];
            [self.view addSubview:panoplayer];
            _panoplayer = panoplayer;
            _panoplayer.panoPlayer.delegate = self;
            _playMovStatus = STATUS_BUFFER_EMPTY;
            // 播放模式
    //        [_panoplayer setViewMode:5];
            // 开启陀螺仪
            self.panoplayer.gyroEnable = YES;
    //        self.panoplayer.panoPlayer.gyroEnable = YES;
            [panoplayer mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.equalTo(@0);
            }];
        }
        return _panoplayer;
    }
    
    - (PicOrMovItem *)item{
        if (nil == _item) {
    //       这些选项就是明面意思 
            _item = [PicOrMovItem new];
            _item.fromWhere = DataFromLocal;
            _item.isLiveShow = NO;
            _item.fileType = 2; // 1,图片 2,视频
            NSString *path = [[NSBundle mainBundle] pathForResource:@"2016_032_pano.mp4" ofType:nil];
            path = [NSString stringWithFormat:@"file://%@",path];
            // 网络视频直接UrlString
            _item.url = path;
            _item.title = @"本地视频";
        }
        return  _item;
    }
    

    XML非常关键,一般我们需要替换的就俩:type和url

    #pragma mark - 视频源替换
    - (void)setupResource{
        // 创建XML
    //    PanoPlayerUrl *panoPlayerUrl = [[PanoPlayerUrl alloc]init];
        NSString *tpl = @"<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \
        <DetuVr> \
        <settings init=\"pano1\" initmode=\"default\" enablevr=\"false\" title=\"\"></settings> \
        \
        \
        <scenes> \
        <scene name=\"pano1\" title=\"\" thumburl=\"\"> \
        <preview url=\"\" /> \
        <image type=\"video\"  url=\"%url\" \
        \
        \
        device=\"0\" \
        \
        /> <view hlookat='0' vlookat='90' fov='110' viewmode='default' /> \
        </scene> \
        </scenes> \
        </DetuVr>";
    
        tpl =  [tpl stringByReplacingOccurrencesOfString:@"%url" withString:self.item.url];
        PanoPlayerUrl *panoplayerurl = [[PanoPlayerUrl alloc] init];
        [panoplayerurl SetXmlContent:tpl];
        [self.panoplayer.panoPlayer Play:panoplayerurl];
    
    }
    

    进行重复播放设置

    #pragma mark - PanoPlayer delegate
    -(void)PluginVideoOnStatusChanged:(PanoVideoPluginStatus)s{
        self.playMovStatus = s;
        switch (s) {
            case STATUS_PLAYING: {
                
                break;
            }
            case STATUS_PAUSE: {
                
                break;
            }
            case STATUS_STOP: {
                NSLog(@"stop test");
                // 在此进行重播
                self.playMovStatus = STATUS_PLAYING;
                [self setupResource];
                break;
            }
            case STATUS_FINISH:{
    //            self.playMovStatus = STATUS_PLAYING;
                NSLog(@"finish test");
                break;
            }
            case STATUS_BUFFER_EMPTY:{
                
                break;
            }
            default: {
                break;
            }
        }
    }
    

    播放器必须销毁

    //销毁播放器
    -(void)dealloc{
        
        [self clearPlayer];
        [self.panoplayer removeFromSuperview];
    }
    
    // 销毁播放器
    -(void)clearPlayer{
        
        if(self.panoplayer.panoPlayer){
            [self.panoplayer.panoPlayer cleargc];
            self.panoplayer.panoPlayer = nil;
        }
    }
    

    才刚刚接触VR播放,共同进步吧!

    相关文章

      网友评论

        本文标题:VR---得图SDK VR视频简单播放

        本文链接:https://www.haomeiwen.com/subject/pgtumttx.html