2

我很努力地播放視頻,這是一個服務器上的視頻文件的網址。我有一個從Web服務中顯示網址的視圖。當我點擊網址(包含在表格單元格中)時,我希望在播放視頻的電影播放器​​上出現新的視圖。我已經嘗試MPMoviePlayerViewControllerMPMoviePlayerController以及兩者的各種組合,但我無法在模擬器上播放視頻。目前我沒有設備,所以請在回答時考慮模擬器和設備。目前我使用:使用網址播放視頻ios 6

NSURL *url = [NSURL fileURLWithPath:filePath]; 
self.player= [[ MPMoviePlayerViewController alloc] initWithContentURL:url]; 
//self.player.navigationController.navigationBar.hidden = YES; 
[self.player.moviePlayer prepareToPlay]; 
//self.player.moviePlayer.scalingMode = MPMovieScalingModeAspectFit; 
self.player.moviePlayer.controlStyle = MPMovieControlStyleNone; 
self.player.moviePlayer.movieSourceType = MPMovieSourceTypeFile; 
self.player.moviePlayer.fullscreen = NO; 
[self presentModalViewController:self.player animated:NO]; 
[self.player.moviePlayer play]; 

filepath是包含視頻網址nsstring

回答

5

替換您此行:NSURL *url = [NSURL fileURLWithPath:filePath];

與此:NSURL *url=[NSURL URLWithString:filePath]; &然後再試。

我使用MPMOVIEPLAYERVIEWCONTROLLER我的代碼:

NSData *geturl = [[videoparsing objectAtIndex:btntag]objectForKey:@"iurl"]; 
    myString = [[NSString alloc] initWithData:geturl encoding:NSASCIIStringEncoding]; 
    NSLog(@"myString..%@",myString); 
    NSURL *fileURL=[NSURL URLWithString:myString]; 
    NSLog(@"fileURL..%@",fileURL); 
    moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL]; 
    [self presentMoviePlayerViewControllerAnimated:moviePlayerController]; 
    [moviePlayerController.moviePlayer prepareToPlay]; 
    moviePlayerController.moviePlayer.shouldAutoplay=YES; 
    [moviePlayerController.moviePlayer play]; 
+0

不working..still停留在載入中... – user1845209

+0

我更新我的答案,你看我是什麼做&然後做出改變acc。你需要... – Vishal

1

如果video fileserver然後

NSURL *url=[NSURL URLWithString:filePath]; 

其他應改變movieSourceTypeMPMovieSourceTypeStreaming

self.player.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming; 

而且

self.player.moviePlayer.fullscreen = YES; 

編輯:地址:

self.player.moviePlayer.shouldAutoplay=YES; 

刪除:

[self.player.moviePlayer play]; 
+0

試過沒有運氣 – user1845209

+0

請參閱http://stackoverflow.com/a/8864540/1106035 –