MPMoviePlayer playing audio but not video when seeking into a file

大憨熊 提交于 2020-01-04 01:39:20

问题


I'm trying to seek into a video file at a certain point. Lets say the video is 5 minutes long and I'm jumping in at 110 seconds.

When I play from the beginning, everything plays through fine, however, when I try to seek into the file, I can hear the audio but I can't see the video. I first thought this was maybe an issue with the order I'm loading the subviews but I can still see (and use) the controls for the player. Sliding back to 0:00 starts the video.

The following is code from my video class. The initIntoView method accepts a UIView and then returns an amended copy which then gets written to the main view. Sorry in advance for the messy code. I'm still quite new to Objective-C.

Init the Video view

- (WWFVideo*) initIntoView: (UIView*) view withContent:(NSDictionary*)contentDict{
    self=[super init];
    viewRef=view;
    contentData = contentDict;
    NSURL *videoUrl = [[NSURL alloc]initWithString:[contentDict objectForKey:@"cnloc"]]; //Returns a HTTP link to my video file (MP4, H.246, AAC Audio)
    videoController = [[MPMoviePlayerController alloc] init];
    videoController.movieSourceType = MPMovieSourceTypeFile;
    [videoController setContentURL:videoUrl];   
    videoController.view.frame = viewRef.bounds;
    [videoController.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
    [viewRef addSubview:videoController.view];
    return self;
}

Start playing the video

-(void)play:(int)offset { //Offset is "110"
    [videoController setInitialPlaybackTime:offset];
    [videoController play];
}

I've tried adding the videoController to viewRef both before and after the video starts playing but it has the same outcome.

I've also tried using an MPMoviePlayerViewController with no avail.

Another thing I tried was changing the streaming type to MPMovieSourceTypeStreaming but it seemed to have no effect.

If I've missed any more vital code, just ask and I'll see what I can do.

Edit:
Xcode 4.6.3
iOS 6
Testing on an iPad 2

Edit #2:
Works perfectly on the simulator, just not on the device.


回答1:


After trying to piece together a sample app to upload here, I found that the w3 version of Big Buck Bunny worked fine. This indicates it was an encoding problem and not an objective C issue.

I've re-encoded the same file I was trying to play before but now with the baseline profile with the following command:

ffmpeg -i {filename} -acodec aac -ac 2 -strict experimental -ab 160k -s {ssize} -vcodec libx264 -preset slow -profile:v baseline -level 30 -maxrate 10000000 -bufsize 10000000 -b 1200k -f mp4 -threads 0 {filename}.ipad.mp4

I found this code on here through this Stack Overflow post.

Primarily for low-cost applications that require additional data loss robustness, this profile is used in some videoconferencing and mobile applications. This profile includes all features that are supported in the Constrained Baseline Profile, plus three additional features that can be used for loss robustness (or for other purposes such as low-delay multi-point video stream compositing). The importance of this profile has faded somewhat since the definition of the Constrained Baseline Profile in 2009. All Constrained Baseline Profile bitstreams are also considered to be Baseline Profile bitstreams, as these two profiles share the same profile identifier code value.

-From Wikipedia

I realise this may not help anyone here looking for Objective-C help but if it saves just one person the 5 hours I spent today trying to get this working, this will be worth it.



来源:https://stackoverflow.com/questions/18593706/mpmovieplayer-playing-audio-but-not-video-when-seeking-into-a-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!