How to play a video starting from specific point on iOS 9 - ios

I'm playing video using MPMoviePlayerController and I need to play it starting from a given point by this code:
MPMoviePlayerController *player;
[player setCurrentPlaybackTime:from];
[player setInitialPlaybackTime:from];
[player setEndPlaybackTime:to];
[player prepareToPlay];
[player play];
But it doesn't work, the video always plays from beginning.
I've seen on Apple Docs that initialPlaybackTime is deprecated in iOS 9 (as well as endPlaybackTime). Does it mean than it will not work on iOS 9? I tried to run this code on iOS 8.4, but the result is the same: the video always plays from the very beginning.
How to make it play from a given point?
Thank you!

Use AVPlayer instead of MPMoviePlayer. It will give you more control over Media playback.
See this (AVPlayer)

Related

AVPlayer video preview issue iOS 14.0.1

I am trying to play local and remote videos using AVPlayer and AVPlayerViewController but I am facing an issue. The player is playing the audio for video but not showing the preview.
It is working fine on all the iOS versions less than iOS 14.0.1.
Please help me on this issue
Here is the sample code
movieUrl = [NSURL fileURLWithPath:filePath];
AVPlayer *player = [AVPlayer playerWithURL:movieUrl];
theMoviPlayer = [[AVPlayerViewController alloc] init];
theMoviPlayer.player = player;
[self addSubview:theMoviPlayer.view];
theMoviPlayer.view.frame = self.bounds;
[theMoviPlayer.player play];
Look at this image for better understanding
I have found the actual reason of this issue. It seems that for certain non-standard encoding or fps, AVPlayer is not able to play video. I have exported the same video in correct encoding using some tool i.e, QuickTimePayer, and the video is playable now.
This issue is only producing on iOS 14.0.1, may be it is a bug/feature in AVPlayer in this update.
Conclusion:
Always check your video encoding if your video is not playing or you are just hearing only audio without any video frames.

AVPlayerViewController stuck on first frame of local video

In one of my ViewControllers, I have an AVPlayerViewController. In my viewDidLoad I have
self.videoPlayerController = [AVPlayerViewController new];
Then, I play a video using the following method
- (void)playVideo:(NSURL*)videoURL {
[self presentViewController:self.videoPlayerController animated:YES completion:^(){
AVPlayer *player = [[AVPlayer alloc] initWithURL:videoURL];
[self.videoPlayerController setVideoGravity:AVLayerVideoGravityResizeAspect];
[self.videoPlayerController setPlayer:player];
[self.videoPlayerController.player play];
}];
}
When playing a video for the first time, the AVPlayerViewController appears, but the video is stuck on the first frame, and will not play. No audio plays either.
In iOS 10.0, the seekbar in the on screen controls show that the video is playing (it will progress to the end). In iOS 10.2 however, the seekbar is stuck at 0:00 as well.
I am experiencing this problem on iPads with iOS versions 10.0 and 10.2, however, it works in the XCode simulator (both 10.0 and 10.2).
My problem is similar in nature to this.
Also, the video plays correctly if you close the ViewController containing the AVPlayerViewController, reopen it, and attempt to play the video again.
I guess that the problem is in your video file. Try to download another video mp4 video sample. Add it to your project and try.

AVPlayerViewController forward and rewind button disabled for hls stream but working for mp4 stream

AVPlayerViewController forward/rewind buttons beside the play button do not seem to work for HLS, but work for an mp4 stream (non - local, played from internet). How can I get it working for HLS? Is there any separate way to make it work for HLS?
This is not supported by the player. You can disable those buttons using the code below:
if([playerItem canStepBackward] && [playerItem canStepForward]){
[playerViewController setShowsPlaybackControls:YES];
}
else{
[playerViewController setShowsPlaybackControls:NO];
}

iOS Increase volume of each sound played

I am using AVAudioSession and AVAudioPlayer calling the steps below in my code. However, the sound is not playing on my specified number.
Here is the code:
[playSoundURL1 play];
[playSoundURL1 setVolume:(0.5)];

prevent MPMoviePlayerController from automatically playing in iOS 4.2.1

I have an MPMoviePlayerController where I load a video from a URL. In iOS 3.2.2 the video started downloading when I added it to a view, but it didn't play until I hit the play button (which is what I want). However, since iOS 4.2.1 came out, it started behaving differently; the video starts downloading and plays automatically.
Here's how I load my MPMoviePlayerController:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc]
initWithContentURL:[NSURL URLWithString:theVideo.fileUrl]];
player.view.frame = articleVideoFrame;
[mainView addSubview:player.view];
I even tried to perform a [player pause]; after the addSubview part, but it still plays automatically. Could you guys help me with this one?
Got it! I used player.shouldAutoplay = NO; and that did the trick. Documentation says it is by default YES, which explains it all. Probably in 3.2 default was NO, but has been switched in 4.2.
I have noticed some other behavior changes in video playback in 4.2.1...namely the video player does not become visible until it starts receiving the data for the movie...
In the previous versions it used to come up instantaneously with "Loading movie..." text on top.
Sometimes, the player gets stuck in when not in full screen mode, with no Done button available or not responding to touches on Pause and Zoom...
I am having other more subtle issues with the playback but I can't isolate the issue just yet...

Resources