2011-09-22 64 views
0

我在我的應用程序中有一個帶有許多選項卡的選項卡視圖,並且在其中一個選項卡中有一個按鈕,單擊時我想在視圖中顯示電影流。我有這樣的代碼:在另一個視圖中打開電影流

NSString *moviePath = @"http://10.0.0.4/prog_index.m3u8"; 

theMovie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:moviePath]]; 

[theMovie.view setFrame:CGRectMake(0, 0, (self.view.frame.size.width), (self.view.frame.size.height))]; 

theMovie.view.backgroundColor = [UIColor grayColor]; 
theMovie.view.tag = 9999; 

[self.view addSubview:[theMovie view]]; 

[theMovie play]; 

該視圖出現,但視頻無法啓動。哪裏不對?有人可以提供一些提示嗎?

感謝

回答

-1

你傳遞給 MPMoviePlayerController指向M3U8文件的URL。這是一個播放列表。要使用 MPMoviePlayerController播放媒體,您必須將其設置爲實際的視頻文件。您應該解析播放列表以獲取到真實視頻的鏈接,然後使用真實鏈接啓動您的 MPMoviePlayerController

檢查M3U - WikipediaMPMoviePlayerController reference

還要檢查這個 related question

編輯:感謝Hugo Silva,我意識到MPMoviePlayerController能夠在M3U8格式播放實時視頻流,因爲我從來沒見過什麼在你的代碼中出現錯誤,我建議你檢查它是否是你的流的問題。嘗試使用Apple提供的samples之一。另外請確保您的數據流符合Apple的要求HTTP Streaming

+0

但是在相關問題中,他說我可以播放播放列表文件,MPMoviePlayerController可以播放其他文件。 –

+0

你是對的,我完全錯了,我試圖找出你的代碼有什麼問題 – ender

+0

我編輯了我的anser,看一看 – ender

相關問題