iPhone MPMoviePlayer 没有视频

发布于 2024-11-16 23:49:18 字数 1876 浏览 2 评论 0原文

这是应该播放实时视频/音频流的代码, 它工作得很好,但唯一的问题是它不显示视频, 只有音频没有视频...

#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

This is code supposed to play live video/audio stream,
it work's fine, but the single problem is that it doesnt show the video,
only the audio comes not the video...

#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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏天碎花小短裙 2024-11-23 23:49:18

如果您使用的是 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];
}  

If you are using iOS < 4.0 then this would happen. Because in iOS 4.0 there is new Class for playing video. Hope below code helps you.

-(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];
}  
泛泛之交 2024-11-23 23:49:18

我是这样写的。感谢您的帮助

-(void)awakeFromNib{
[self playMovieFromLocalPath:@"http://eu01.kure.tv:1935/liveedge/shaber.smil/playlist.m3u8"];
}

ı wrote this way.thanks for your helps

-(void)awakeFromNib{
[self playMovieFromLocalPath:@"http://eu01.kure.tv:1935/liveedge/shaber.smil/playlist.m3u8"];
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文