我使用此代碼player.duration顯示的MPMoviePlayerController始終爲零的視頻文件
MPMoviePlayerController *player = [[MPMoviePlayerController alloc]
initWithContentURL:[NSURL fileURLWithPath:videostr]];
其中videostr是視頻文件的路徑打起了小視頻mpmediaplayer控制器。
現在我需要獲得該視頻文件的長度,因爲我使用此代碼。
length = player.duration;
但它始終顯示爲0.000。但視頻播放良好。
我通過使用Google搜索每個地方檢查代碼來獲得視頻持續時間只有player.duration
。
,我嘗試一些其他的代碼也
AVURLAsset *asset = [[[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:videostr]
options:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], AVURLAssetPreferPreciseDurationAndTimingKey, nil]] autorelease];
NSTimeInterval duration;
if (asset)
duration = CMTimeGetSeconds(asset.duration) ;
NSLog(@">>>>>>>>>>>>>>>>>>>> %f", asset.duration);
即使它顯示zero.Can任何一個請幫助我。
提前致謝。
通知:MPMoviePlayerLoadStateDidChangeNotification 調用2次automatiaclly – g212gs 2014-06-28 09:00:21
如果默認視頻暫停,則此解決方案不起作用,因爲當用戶執行播放操作時會調用此通知。以任何方式獲得持續時間? – jose920405 2015-06-24 14:15:13