iPhone MPMoviePlayer нет видео - PullRequest
       6

iPhone MPMoviePlayer нет видео

0 голосов
/ 24 июня 2011

Это код, предназначенный для воспроизведения живого видео / аудио потока, он работает нормально, но единственная проблема заключается в том, что он не показывает видео, только звук приходит не видео ...

#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

Ответы [ 2 ]

0 голосов
/ 24 июня 2011

Я написал так. Спасибо за вашу помощь

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

0 голосов
/ 24 июня 2011

Если вы используете iOS <4.0, это может произойти. Потому что в iOS 4.0 появился новый класс для воспроизведения видео. Надеюсь, приведенный ниже код поможет вам. </p>

-(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];
}  
...