iPhone MPMoviePlayer无视频
这是用来播放实时视频/音频流的代码, 它工作正常,但唯一的问题是它不显示视频, 只有音频而不是视频iPhone MPMoviePlayer无视频,iphone,xcode,mpmovieplayer,live-streaming,Iphone,Xcode,Mpmovieplayer,Live Streaming,这是用来播放实时视频/音频流的代码, 它工作正常,但唯一的问题是它不显示视频, 只有音频而不是视频 #import <MediaPlayer/MediaPlayer.h> @implementation movieplayerViewController -(void)awakeFromNib{ NSURL *mediaURL = [NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipb
#import <MediaPlayer/MediaPlayer.h>
@implementation movieplayerViewController
-(void)awakeFromNib{
NSURL *mediaURL = [NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:mediaURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[mp setControlStyle:MPMovieControlStyleFullscreen];
[mp setMovieSourceType:MPMovieSourceTypeStreaming];
[mp setFullscreen:YES];
[self.view addSubview:[mp view]];
[mp prepareToPlay];
[mp play];
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
NSError *error = [[notification userInfo] objectForKey:@"error"];
if (error) {
NSLog(@"Did finish with error: %@", error);
}
}
- (void)dealloc
{
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
如果您使用的是iOS<4.0,则会发生这种情况。因为在iOS 4.0中有一个播放视频的新类。希望下面的代码对您有所帮助
-(void)playMovieFromLocalPath:(NSString *)strPath{
NSURL *movieURL = [[NSURL alloc]initFileURLWithPath:strPath];
NSString *strVersion = [[UIDevice currentDevice] systemVersion];
float version = [strVersion floatValue];
if(version < 4.0){
MPMoviePlayerController *themovie = [[MPMoviePlayerController alloc]initWithContentURL:movieURL];
themovie.scalingMode=MPMovieScalingModeAspectFill;
[themovie play];
}
else{
MPMoviePlayerViewController *themovie = [[MPMoviePlayerViewController alloc]initWithContentURL:movieURL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(DidFinishPlaybackWithReason:) name:MPMoviePlayerPlaybackDidFinishNotification object:themovie.moviePlayer];
[self presentMoviePlayerViewControllerAnimated:themovie];
}
}
-(void)DidFinishPlaybackWithReason:(NSNotification *)aNotification{
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player stop];
[self dismissMoviePlayerViewControllerAnimated];
}
ı是这样写的。谢谢你的帮助 -虚空{ [自播放电影自本地路径:@http://eu01.kure.tv:1935/liveedge/shaber.smil/playlist.m3u8]; }
谢谢你,伙计,最后一个问题是如何/在哪里插入我的url?只需像这样调用此函数:[self playmoviefromlocapath:@;