MPMoviePlayerController的一些用法

1.計算使用MPMoviePlayerController播放的視頻的長度有兩種方法:


第一種方法

NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO]                                           forKey:AVURLAssetPreferPreciseDurationAndTimingKey]; 

AVURLAsset *urlAsset = [AVURLAssetURLAssetWithURL:videoUrloptions:opts]; 

NSInteger totalSecond = urlAsset.duration.value / urlAsset.duration.timescale; 

使用上述代碼需要插入AVFoundation框架。播過我用這種方法計算視頻長度時,會延遲其後代碼的執行,不知道什麼原因。


第二種方法

使用MPMoviePlayerController的duration屬性,當MPMoviePlayerController的duration未知時默認爲0.0,如果duration確定,會發送MPMovieDurationAvailableNotification通知,接着duration的值將會更新爲播放視頻的長度,單位是秒。


2.視頻什麼時候開始播放


當視頻開始播放時會發送MPMediaPlaybackIsPreparedToPlayDidChangeNotification,所以你只需要在註冊

MPMediaPlaybackIsPreparedToPlayDidChangeNotification通知,當接收到此通知說明視頻開始播放。


3.自定義播放器視圖時怎麼自定義聲音控件


使用MPVolumeView控制系統的聲音大小。通過改變MPVolumeView slider的值可以改變系統的聲音,同時通過調節系統的聲音按鈕,slider的值也會跟着改變。

volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(310, 180, 100, 20)];

volumeView.showsVolumeSlider = YES;

[backView addSubview:volumeView];

[volumeView release];


4.通過presentModalViewController調出MPMoviePlayer所在控制器,當通過dismissModalViewController移除控制器時,手機的狀態欄可能會消失。解決辦法:在dismissModalViewController調用函數

movieplayer.controlStyle = MPMovieControlStyleFullScreen;

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC), dispatch_get_current_queue(), ^{

        [UIApplication sharedApplication].statusBarHidden = NO;

    });




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章