2011-06-24 5 views
0

ビデオなし、 それの仕事の罰金が、単一の問題が...それは、 のみ音声が映像なくなるビデオを表示doesntのことiPhone MPMoviePlayerこれは、コードのライブビデオ/オーディオストリームを再生することになっている

です
#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 

答えて

0

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]; 
} 
+0

を支援するために、これはway.thanks書いた私は私のURLを挿入する方法/ 1最後の質問ニル、チームメイトありがとう? – Somon

+0

この関数を次のように呼び出してください:[self playMovieFromLocalPath:@ "http://www.abc.com/xyz.mp4"]; – Deeps

0

私はあなたが

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

関連する問題