2013-11-15 143 views
0

我嘗試使用此URL從Dropbox播放視頻:http://www.dropbox.com/s/usqbtrjgcxu0ac6/pandaw.m4v但是當我播放時,它變成黑色,我感到震驚。無法使用ios本地播放器從drobox播放視頻

誰能告訴我如何在這裏定義網址,我認爲我的網址是不正確的,爲什麼我不能玩。

我的代碼:

self.moviePlayerController = 
[[MPMoviePlayerController alloc] initWithContentURL:[[NSURL alloc] initWithString:@"http://www.dropbox.com/s/usqbtrjgcxu0ac6/pandaw.m4v"]];//http://www.youtube.com/watch?v=x3TIBhQy3XY 

//的NSString * videoFileName = [[一個NSBundle mainBundle] pathForResource:@ 「pandaw」 ofType:@ 「M4V」 inDirectory:無]; // self.movi​​ePlayerController = // [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:videoFileName]];

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(moviePlayerDidExitFullscreen:) 
              name:MPMoviePlayerDidExitFullscreenNotification 
              object:nil]; 


[self.moviePlayerController prepareToPlay]; 
self.moviePlayerController.backgroundView.backgroundColor=[UIColor purpleColor]; 
[self.moviePlayerController setFullscreen:YES]; 
self.moviePlayerController.useApplicationAudioSession = NO; 
self.moviePlayerController.movieSourceType=MPMovieSourceTypeStreaming; 
[self.moviePlayerController.view setFrame:self.view.bounds]; 
[self.view addSubview:self.moviePlayerController.view]; 

if (self.moviePlayerController.isPreparedToPlay==YES) { 
    [self.moviePlayerController play]; 
}else{ 
    NSLog(@"not yet finish in preparing"); 
} 

感謝您的幫助!

回答

0

DropBox不允許直接訪問它的文件,你只能通過使用它的api來訪問DropBox中的文件。所以

首先我要你去嘗試得到視頻的短網址以這種方式和在本地播放器

NSString *urlString=[NSString stringWithFormat:@"https://api.dropbox.com/1/shares/dropbox%@?access_token=%@",selectedImagePath,dropBoxToken]; 

提供該URL如果仍然沒有成功,那麼唯一的辦法就是下載文件,您可以下載文件這條路。

NSString *imageUrlString=[NSString stringWithFormat:@"https://api-content.dropbox.com/1/files/dropbox%@?access_token=%@",path,dropBoxToken]; 

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:imageUrlString]]; 

[theRequest setHTTPMethod:@"GET"]; 

NSData *returnData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil]; 

注:我不知道DropBox的支持直播或不