您的位置:首页 > 其它

VLCMediaPlayer

2015-03-14 18:12 330 查看
VLCMediaPlayer比苹果自带的播放器更强大,用法:

#import <UIKit/UIKit.h>

#import <MobileVLCKit/MobileVLCKit.h>

@interface ViewController : UIViewController {

    UIView *videoView;

    

    VLCMediaPlayer *vlcPlayer;

}

@end

#import "ViewController.h"

/* 确保选中 GNU C++ 而不是Apple的C++ */

@implementation ViewController

            

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    

    

    videoView = [[UIView alloc] initWithFrame:CGRectMake(10, 80, 300, 300)];

    videoView.backgroundColor = [UIColor blackColor];

    [self.view addSubview:videoView];

    

    // 1. 创建一个播放器

    vlcPlayer = [[VLCMediaPlayer alloc] initWithOptions:nil];

    // 2. 让videoView作为vlc的视频播放的内容

    vlcPlayer.drawable = videoView;

    

    UIButton *b = [UIButton buttonWithType:UIButtonTypeSystem];

    b.frame = CGRectMake(100, 30, 100, 40);

    [b setTitle:@"开始播放" forState:UIControlStateNormal];

    [b addTarget:self action:@selector(playVlc:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:b];

}

- (void) playVlc:(UIButton *)b {

    NSString *urlpath = @"http://zb.v.qq.com:1863/?progid=4035478592";

//    urlpath = @"http://192.168.88.10/app/qfts/ms/friends/0101/0101.m3u8";

//    urlpath = @"rtsp://192.168.88.20:1935/live/yangcam";

    NSURL *url = [NSURL URLWithString:urlpath];

    // 3. 创建一个播放对象

    VLCMedia *item = [[VLCMedia alloc] initWithURL:url];

    [vlcPlayer setMedia:item];

    [vlcPlayer play];

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: