iOS 本地视频和网络视频流播放实例代码

2020-01-20 23:29:18于海丽

 链接: https://www.easck.com/s/1pLz7DTx密码: te5p

第二步: 将下载下来的zip解压,MobileVLCKit文件夹中的MobileVLCKit.framework 拖入到你的工程中

iOS,本地视频播放,ios播放网络音频流

第四步: 选择finish

iOS,本地视频播放,ios播放网络音频流

第五步:添加依赖库

1:  AudioToolbox.framework

2:  VideoToolbox.framework

3:  CoreMedia.framework

4:  CoreVideo.framework

5:  CoreAudio.framework

6:  AVFoundation.framework

7:  MediaPlayer.framework

8:  libstdc++.6.0.9.tbd

9:  libiconv.2.tbd

10: libc++.1.tbd

11: libz.1.tbd

12: libbz2.1.0.tbd

 共12个

完成之后如图所示:

iOS,本地视频播放,ios播放网络音频流

第六步: 使用框架

ViewController.h


#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

//视频流的路径,外界传过来的视频流的地址
@property (nonatomic, copy) NSString * rtspPath;

@end

 ViewController.m


#import "ViewController.h"
#import <MobileVLCKit/MobileVLCKit.h>

//屏幕宽高的宏
#define EYScreenWidth [[UIScreen mainScreen] bounds].size.width
#define EYScreenHeight [[UIScreen mainScreen] bounds].size.height

@interface ViewController ()

//视频播放
@property (nonatomic, strong) VLCMediaPlayer *player;

@end

@implementation ViewController

- (void)viewDidLoad {
 [super viewDidLoad];

 //1.创建播放视图,模拟器测试会有问题!!!真机可以正常播放
 UIView *videoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EYScreenWidth, EYScreenHeight)];
 [self.view addSubview:videoView];

 //2.创建播放器
 self.player = [[VLCMediaPlayer alloc] initWithOptions:nil];

 //3.设置播放图层
 self.player.drawable = videoView;

 //4.设置播放的路径
 self.player.media = [VLCMedia mediaWithURL:[NSURL URLWithString:self.rtspPath]];

 //5.开始播放
 [self.player play];
}

- (void)dealloc
{
 if (self.player.isPlaying) {
  [self.player stop];
 }
}

@end

第七步: 真机测试

Command + R 运行报错

iOS,本地视频播放,ios播放网络音频流

 在工程设置中,Setting搜索bitcode,将Yes修改为No

iOS,本地视频播放,ios播放网络音频流