2012-05-17 51 views
2

我要玩一個視頻鏈接:www.mysite.com/iphone/video.mp4IOS 5 - 如何播放視頻與web網址

我使用的iOS5和的MPMoviePlayerController我試着用下面的代碼但它只顯示黑色頁面:

MPMoviePlayerController *player=[[MPMoviePlayerController alloc]initWithContentURL:[NSURL URLWithString:@"http://www.mysite.com/iphone/video.mp4"]];            [[player view] setFrame:[self.view.bounds]];                      [self.view addSubview:[player view]]; [player play]; 

是否有可能通過網址鏈接播放視頻?我有很多的視頻,所以我不希望把他們在我的項目,所以我需要從網絡播放

@Edit:我用例子做了它所使用流,但解決我的問題,因爲apple's developer site

我使用網址。感謝所有答案

+0

檢查視頻存在與否對URL要從 – Mangesh

+0

取我嘗試使用的URL:http:/ /www.ebookfrenzy.com/ios_book/movie/movie.mov但不能播放 – ercan

+0

呃ercan,你有解決方案b'cos im面臨同樣的問題(無法播放視頻使用w eb網址)。如果你有答案,那麼請分享哪些對我們有用。感謝 – Priyanka

回答

0

試試這個

NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"3idiots.mov" ofType:nil]; 
    NSURL *url = [NSURL fileURLWithPath:urlStr]; 
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 
    [self.view addSubview:moviePlayer.view]; 
    moviePlayer.view.frame = CGRectMake(0, 0, 300, 400); 
    [moviePlayer play]; 
+1

我的問題是從網址播放mov或mp4文件。我的視頻不在我的項目中,所以我認爲這個軟件包不是我的解決方案。但我絕望地嘗試你的代碼崩潰,錯誤說:[NSURL initFileUrlWithPath:]:零字符串參數。我只更改代碼中的pathForResource參數。 – ercan

0

如果你有流媒體服務器和準備,這是很容易實現視頻控制器彈出YouTube的風格。

Writing an app to stream video to iPhone

+0

嗨,我們沒有流媒體服務器,所以不可能從鏈接播放視頻?我們只有一個簡單的Windows主機。 – ercan

+0

它也可以工作。請嘗試一次 – Mangesh

0

刪除

NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"3idiots.mov" ofType:nil]; 

通網址像thislike這樣,

NSURL *videoURL = [NSURL URLWithString:@"http://www.youtube.com/v/HGd9qAfpZio&hl=en_US&fs=1&"]; 
+1

:(不幸的是,它不工作:(有沒有人嘗試過,並取得成功?或者我嘗試一個不可能的事情? – ercan

+0

什麼是你鏈接到的視頻?:O –

+0

這不是一個有用的我相信這是笑話。 –