AVPlayer video preview issue iOS 14.0.1 - ios

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.

Related

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.

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

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)

MKV player in my iOS app

How can I play mkv video into my iOS App?
Can I use MPMoviePlayerController and add to it mkv codecs?
I try to load an mkv from an URL into my MPMoviePlayerController
NSURL *videoStreamURL = [NSURL URLWithString:#"mkvURL"];
mediaPlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoStreamURL];
But a black screen, with nothing in it to play, appears.
The simple answer is no.
You can use FFMPEG to accomplish this using https://github.com/iMoreApps/ffmpeg-avplayer-for-ios

buffer video before playing it on iphone

I'm doing some testing which during I would like to:
- Take a video that is in the app folder
- load that video to memory (buffer it)
- play the bufferd frames from the memory
All made on iPhone
Actually,
I would like to play a video from memory.
(I also want to load the video to memory by frames).
I hope it clear enough.
How can I accomplish this?
Tnx
EDIT:
Maybe I can point my question a little more..
I have a server that streams video via UDP (let's say that for the simuloation I'm using VLC to stream via UDP).
What do I have to do and implement in order to get the UDP stream from VLC and display it on the screen of my I device (of course i'm talking about writing code and not using VLC streamer :-) ).
Hope that's better and that I'll get some answers now.
Tnx
A video has to be buffered only if you receive the video from a server over internet via packets/Streams.
Else you can just play the video using below code:-
NSURL *url = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:#"yourVideo" ofType:#"yourVideoType" inDirectory:#""]];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[player view] setFrame:[self.view bounds]];
[self.view addSubview:[player view]];
[player play];
[player release];
You can implement the notification MPMoviePlayerLoadStateDidChangeNotification, if you are playing the videos after fetching over some data service.(GPRS,2G, Internet.)

MPMoviePlayerController is not responding to device volume controls

I'm working on a game that during the title sequence plays a video in the background using MPMoviePlayerController. I overlay my game controls over this (just a few textured UIButtons).
The video itself has no audio, but I'm playing sounds when I press buttons via OpenAL.
The Audio Session is set to "Ambient" and whenever the MPMoviePlayerController is not around it responds correctly to device's mute button and volume. But as soon as the video starts playing it blares out the sounds with no regard to the mute or volume settings.
Can anyone help me? Is the MPMoviePlayerController interfering with the AudioSession state?
Is there a way to stop this from happening. My movie has no sound in it so it shouldn't need to do that.
The MPMoviePlayerController uses the AVAudioPlayer shared instance. So you can literally set the volume of the MPMoviePlayerController and it will turn down your background music. However, a better way is to tell MPMoviePlayerController to not use the shared instance.
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"intro" ofType:#"m4v"]];
self.player = [[MPMoviePlayerController alloc] initWithContentURL:url];
self.player.movieSourceType = MPMovieSourceTypeFile;
**[self.player setUseApplicationAudioSession:FALSE];**

Resources