html 消息流,html-i中HTTP实时流的实现

一个简短的要点实现。 随附的URL指向有效的流(自2015年12月15日起),但是您只需将自己的URL替换为.m3u8文件即可。

目标C:

#import

@interface ViewController ()

@property (strong, nonatomic) MPMoviePlayerController *streamPlayer;

@end

@implementation ViewController

- (void)viewDidLoad

{

[super viewDidLoad];

NSURL *streamURL = [NSURL URLWithString:@"http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8"];

_streamPlayer = [[MPMoviePlayerController alloc] initWithContentURL:streamURL];

// depending on your implementation your view may not have it's bounds set here

// in that case consider calling the following 4 msgs later

[self.streamPlayer.view setFrame: self.view.bounds];

self.streamPlayer.controlStyle = MPMovieControlStyleEmbedded;

[self.view addSubview: self.streamPlayer.view];

[self.streamPlayer play];

}

- (void)dealloc

{

// if non-ARC

// [_streamPlayer release];

// [super dealloc];

}

@end

迅速:

import UIKit

import MediaPlayer

class ViewController: UIViewController {

var streamPlayer : MPMoviePlayerController = MPMoviePlayerController(contentURL: NSURL(string:"http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8"))

//Let's play

override func viewDidLoad() {

super.viewDidLoad()

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

streamPlayer.view.frame = self.view.bounds

self.view.addSubview(streamPlayer.view)

streamPlayer.fullscreen = true

// Play the movie!

streamPlayer.play()

}

}

更新了两种语言的答案。 在iOS 9中也不推荐使用MPMoviePlayerController,但是您可以改用AVPlayerViewController。 快乐编码!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值