2012-02-07 3 views
1

Как играть в URL-адрес сервера в Iphone? как играть видео с URL-адреса, используя MPMoviePlayer?Воспроизвести видеоролик в iphone

(void)loadVideo { 

    videoUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://movies.apple.com/media/us/mac/getamac/2009/apple-mvp-biohazard_suit-us-20090419_480x272.mov"]]; 
     if(videoUrl) { 

     if([videoUrl scheme]) { 

      [self playVideoStream:videoUrl]; 
     } 
    } 
} 

-(void)playVideoStream:(NSURL *)movieFileURL { 

MPMovieSourceType movieSourceType = MPMovieSourceTypeUnknown; 
/* If we have a streaming url then specify the movie source type. */ 
if ([[movieFileURL pathExtension] compare:@"mov" options:NSCaseInsensitiveSearch] == NSOrderedSame) 
{ 
    movieSourceType = MPMovieSourceTypeStreaming; 
} 
[self createAndPlayMovieForURL:movieFileURL sourceType:movieSourceType]; 
} 

-(void)createAndPlayMovieForURL:(NSURL *)movieURL sourceType:(MPMovieSourceType)sourceType { 

/* Play the video! */  
[moviePlayer setMovieSourceType:sourceType]; 
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];; 
moviePlayer.view.frame = CGRectMake(10, 20, 280, 210); 
[customVideoView addSubview:moviePlayer.view]; 
[moviePlayer play]; 
} 
+0

Хорошо, но где вопрос –

ответ

2

Вы должны установить contentURL недвижимость в Fisrt

moviePlayer.contentURL = urlVideo; 

[moviePlayer prepareToPlay]; 
[moviePlayer play]; 
1

попробовать это:

{ 

     NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"//name of your video here" ofType:@"//format e.g. mp4, m4v"]]; 
MPMoviePlayerViewController *playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; 
[self presentMoviePlayerViewControllerAnimated:playerController]; 

playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile; 

[playerController.moviePlayer play]; 


// When movie finished loading you can have a notification and do extra code 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MovieDidLoad:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; 



[playerController release]; 

playerController = nil; 
    } 


    -(void)MovieDidLoad:(NSNotification *)notification { 

    NSLog(@"logged and notification is %@", notification); 

// extra code if needed 


    } 
+0

, если вам нужно подготовиться к игре, введите код: – user1194201

+0

[playerController.moviePlayer prepareToPlay]; – user1194201

0

Один из простой способ заключается в загрузке, что URL-адрес видео в UIWebview.

Смежные вопросы