2011-12-27 35 views
1

我想在UIWebView中播放視頻。這個視頻存儲在我的應用程序(這是本地視頻不是來自服務器)。我不想使用MPMoviePlayerControlleriPhone:如何在WebView中播放本地視頻?

我得到了下面的代碼從SO:

NSString *url = @"http://my_url.com/my_movie_path/"; 
UIWebView* tempAudioPlayer = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)]; 
[tempAudioPlayer loadHTMLString:[NSString stringWithFormat:@"<iframe frameborder=\"0\" width=\"0\" height=\"0\" src=\"%@\"></iframe>", url] baseURL:nil]; 
[self addSubview:tempAudioPlayer]; 

,但它不是爲我工作。

有沒有其他的方法可以在沒有MPMoviePlayerController的情況下播放視頻?

我該怎麼辦?

+1

DUPE http://stackoverflow.com/questions/4836595/playing-a-local-video-in-a-uiwebview – box86rowh 2011-12-27 13:20:15

+0

這裏是本地視頻。 – Devang 2011-12-27 13:24:01

+0

另一方面,請嘗試設置uiwebview的基本路徑。 – box86rowh 2011-12-27 13:45:33

回答

9
NSString *Str = @"<video controls> <source src=\"yourvideofile.mp4\"> </video>"; 
NSString *path = [[NSBundle mainBundle] pathForResource:@"yourvideofile" ofType:@"mp4"]; 
[Webview loadHTMLString:Str baseURL:[NSURL fileURLWithPath:path]]; 
+0

它播放'.mov'文件嗎? – Devang 2011-12-28 04:23:21

+2

你可以嘗試你的運氣,只需製作新的樣本視圖基礎項目=>從xib拖拽webview =>使出口和連接出口和複製上面提供的粘貼代碼更改文件名。這將只需要幾分鐘。如果不使用webview,請首先嚐試使用MPMoviePlayer檢查文件和分辨率與iPhone的MOV文件。 – Dhawal 2011-12-28 07:18:42