ios 獲取視頻的總時長

NSURL    *movieURL = [NSURL URLWithString:movieStr];
                    NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO]
                                                                     forKey:AVURLAssetPreferPreciseDurationAndTimingKey];                    
                    AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:movieURL options:opts];  // 初始化視頻媒體文件
                    int minute = 0, second = 0; 
                    second = urlAsset.duration.value / urlAsset.duration.timescale; // 獲取視頻總時長,單位秒
                    //NSLog(@"movie duration : %d", second);                    
                    if (second >= 60) {
                        int index = second / 60;
                        minute = index;
                        second = second - index*60;                        
                    }    

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