Basically i record / import video , it saves to the docs folder and im trying to figure out how to get the length (time) so i can display it for each individual video..
基本上我记录/导入视频,它保存到文档文件夹,我想弄清楚如何获取视频的长度(时间),这样我就可以为每个视频显示视频。
I have a column in the database for it and the neccessary code to display it, just not sure how to get it..
我在数据库中有一列,以及显示它的必要代码,只是不知道如何获得它。
Any help is greatly appreciated
非常感谢您的帮助
1 个解决方案
#1
7
You can get the path to the document and pass it as a file URL into the MediaPlayer framework to get info about the video file. Here's code to get the duration in seconds of a movie file:
您可以获取文档的路径,并将其作为文件URL传递到MediaPlayer框架中,以获得关于视频文件的信息。以下代码以秒为单位获取电影文件的持续时间:
NSArray *docsPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsFolder = [docsPaths objectAtIndex:0];
NSString *movieFilePath = [documentsFolder stringByAppendingPathComponent:@"Movie.mov"];
MPMoviePlayerController *player = [[[MPMoviePlayerController alloc] initWithContentURL] autorelease];
NSTimeInterval duration = player.duration; // in seconds
#1
7
You can get the path to the document and pass it as a file URL into the MediaPlayer framework to get info about the video file. Here's code to get the duration in seconds of a movie file:
您可以获取文档的路径,并将其作为文件URL传递到MediaPlayer框架中,以获得关于视频文件的信息。以下代码以秒为单位获取电影文件的持续时间:
NSArray *docsPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsFolder = [docsPaths objectAtIndex:0];
NSString *movieFilePath = [documentsFolder stringByAppendingPathComponent:@"Movie.mov"];
MPMoviePlayerController *player = [[[MPMoviePlayerController alloc] initWithContentURL] autorelease];
NSTimeInterval duration = player.duration; // in seconds