我想在iPhone上通过http流式传输* .m3U8视频文件。在iOS 3.2之前,它曾经在iPhone上完美播放。
但是对于MoviePlayer API的最新更改,我无法在iOS4设备上传输此文件。
我现在正在使用MPMoviePlayerViewController对象播放此文件,但每次收到错误“错误代码= 2.文件无法播放”。
错误描述非常不足,Apple的MPMoviePlayerViewController示例代码已过时
请帮助我解决方案或提供示例代码或工作解决方案。
答案 0 :(得分:0)
控制器:
#import <AVFoundation/AVFoundation.h>
@property (nonatomic, retain) AVPlayer *avPlayer;
@property (nonatomic, retain) IBOutlet PlayerView *playerView;
@property (nonatomic, retain) AVPlayerItem *playerItem;
// Use a HTTP URL, example: http://192.168.2.103/video.m3u8
-(void) setUpPlayer:(NSURL*) url {
AVURLAsset *anAssest= [[AVURLAsset alloc]initWithURL:url options:nil];
[anAssest loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:@"tracks"] completionHandler:^{
NSError *error = nil;
AVKeyValueStatus status = [anAssest statusOfValueForKey:@"tracks" error:&error];
if (status == AVKeyValueStatusLoaded) {
self.playerItem = [AVPlayerItem playerItemWithAsset:anAssest];
self.avPlayer = [AVPlayer playerWithPlayerItem:self.playerItem];
self.playerView.player=self.avPlayer;
[self.avPlayer play];
} else {
NSLog(@"The asset's tracks were not loaded:\n%@", [error localizedDescription]);
}
}];
}
观点:
#import <AVFoundation/AVFoundation.h>
#import <UIKit/UIKit.h>
@interface PlayerView : UIView
@property (nonatomic, retain) AVPlayer* player;
@end
#import "PlayerView.h"
@implementation PlayerView
+ (Class)layerClass {
return [AVPlayerLayer class];
}
- (AVPlayer*)player {
return [(AVPlayerLayer*)[self layer] player];
}
- (void)setPlayer:(AVPlayer*)player {
[(AVPlayerLayer*)[self layer] setPlayer:player];
}
@end
类似的东西:P您应该使用Apple的mediafilesegmenter命令创建m3u8,但无论如何它可能会起作用。