美文网首页
集成VLC For iOS 并简单使用

集成VLC For iOS 并简单使用

作者: ZfRee | 来源:发表于2017-07-13 12:45 被阅读1712次

    一、为什么使用VLC For iOS

    因为项目需求要播放rstp流媒体,但我们iOS只支持 mov/mo4/m4v的视频格式,所以就需要一个第三方的框架来帮助我们播放其他格式的视频。

    之前看过直播app的实现,所以我的第一反应是使用ijkplayer。仔细看了看发现集成起来比较复杂,因为还需要导入牛逼的ffmpeg库,这时候我发现了VLC for iOS

    VLC可播放大多数多媒体文件,以及 DVD、音频 CD、VCD 及各类流媒体协议。


    二、集成VLC for iOS

    我们需要将MobileVLCKit.framework这个框架添加到我们的项目

    1. 使用cocoapods(推荐)
    platform:ios,’8.0’  
    target "yourProjectName" do  
    pod 'MobileVLCKit', '~> 2.2.2'  
    end  
    
    1. 手动下载(下载地址)

    现在我们有了MobileVLCKit.framework这个框架,请按照以下步骤配置工程:

    1. 导入 MobileVLCKit.framework 框架(cocoapods方式请忽略)
    2. 在Build Phases -> Linked Frameworks and Libraries 添加依赖库 libiconv、libbz2、libstdc++、AudioToolbox.framework
    3. 将一个文件后缀改为.mm,因为框架底层用到了C++代码
    4. 在Build Setting 设置中 搜索C++ Standard Library 改为GNU模式

    OK! command + B 不爆红? "恩,恭喜你,集成成功了"


    三、代码

    #import <MobileVLCKit/MobileVLCKit.h>
    @property (strong, nonatomic) VLCMediaPlayer *player;
    
    //1.创建视频播放器
    self.player = [[VLCMediaPlayer alloc] init]; 
    
    //2.设置播放的view
    self.player.drawable = self.view;            
    self.player.delegate = self;
    
    //3.设置播放资源路径
    NSURL *remoteUrl = [NSURL URLWithString:@"path"];
    self.player.media = [VLCMedia mediaWithURL:remoteUrl];
    
    //4.开始播放
    [self.player play]; 
    
    - (void)viewWillDisappear:(BOOL)animated
    {
        [super viewWillDisappear:animated];
        [self.player stop];
    }
    
    

    播放面板是什么都没有的,具体UI需要自己根据需求定制,VLC提供的功能要自己去.h文件里学习了,大家加油!

    相关文章

      网友评论

          本文标题:集成VLC For iOS 并简单使用

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