2014-06-20 106 views
0
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    MPMoviePlayerController *player; 
    NSLog(@"%@",gotVideo); 
    NSURL *urlString=[NSURL URLWithString:gotVideo]; 
    player = [[MPMoviePlayerController alloc] initWithContentURL:urlString]; 


    [[NSNotificationCenter defaultCenter] 
    addObserver:self 
    selector:@selector(movieFinishedCallback:) 
    name:MPMoviePlayerPlaybackDidFinishNotification 
    object:player]; 


    //---play movie--- 
    [player play]; 

} 

- (void) movieFinishedCallback:(NSNotification*) aNotification { 
    MPMoviePlayerController *player = [aNotification object]; 
    [[NSNotificationCenter defaultCenter] 
    removeObserver:self 
    name:MPMoviePlayerPlaybackDidFinishNotification 
    object:player]; 
} 

在iOS 7.1模擬器中,視頻未播放。請提供任何建議。從url播放視頻

+1

試了一下在真實設備上? –

+0

NSLog(@「%@」,gotVideo); - 在這個地方你得到的網址 –

+1

正如SergiusGee建議嘗試在設備上。這些移動模擬器在獲取在線資源時經常遇到問題。在android模擬器上最顯着的觀察! – MABVT

回答

0

你忘了出示,或添加爲子視圖

[self presentMoviePlayerViewControllerAnimated:player]; 
//---play movie--- 
[player play]; 
+0

仍然無法正常工作。 – user3664154

+0

然後檢查你的網址,並按照一些簡單的教程http://www.appcoda.com/video-recording-playback-ios-programming/ –

0

試試這個代碼

- (void)viewDidLoad 
    { 
     [super viewDidLoad]; 


NSURL *urlString=[NSURL URLWithString: urlString]; 
     MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: urlString]; 
       [player.view setFrame:CGRectMake(//set rect frame)]; 
       player.controlStyle = MPMovieControlStyleDefault; 
       player.shouldAutoplay=YES; 
       player.repeatMode = NO; 
       [player setFullscreen:YES animated:NO]; 
       [player prepareToPlay]; 
       [player play]; 
    [self.view addsubview: player.view]; 

     [[NSNotificationCenter defaultCenter] 
     addObserver:self 
     selector:@selector(movieFinishedCallback:) 
     name:MPMoviePlayerPlaybackDidFinishNotification 
     object:player]; 

    } 
    - (void) movieFinishedCallback:(NSNotification*) aNotification { 
     MPMoviePlayerController *player = [aNotification object]; 
     [[NSNotificationCenter defaultCenter] 
     removeObserver:self 
     name:MPMoviePlayerPlaybackDidFinishNotification 
     object:player]; 
    } 
+0

不工作@Vibha Singh – user3664154

+0

我認爲你檢查網址..問題不是代碼可能這是由於URL。 –

+0

網址很好,它顯示在瀏覽器上的相應視頻和點擊相同的網址獲得按鈕的縮略圖。現在點擊這個應該會顯示視頻。視頻沒有被播放,而是出現了一個黑框與框架出現 – user3664154