My application is using AVPlayer to play video. There is a serious problem that my app currently experience. Sometimes, it is playing the video very fast although I checked to make sure that I either set the self.player.rate = 0.3 or self.player.rate = 1 or not set the rate at all. This only happens sometimes and it happens to all the videos I have.
Can anyone give me any hint on the current problem?
I finally know the answer. I called [player setRate:0.3] and [player play] at the same time and the second call override the first call, which sets the rate to be 0 (normal). The method setRate: already set the rate for the player and play the video already
Related
I have a small 4 second video file which will be played again and again.For that I have used
[player setRepeatMode:MPMovieRepeatModeOne];
but after the 1st loop I want the audio to be stopped and only video should be played.I tried setting [player setUseApplicationAudioSession:NO];
but its not working.
Any help?
There is no direct way to mute or adjust volume of MPMoviePlayerController. All you need to do is to control your device's volume.
Get MPMoviePlayerPlaybackDidFinishNotification and write Following code in specific check
[[MPMusicPlayerController applicationMusicPlayer] setVolume:0];
I don't think there is a ready to use option to count loops.
I would recommend to extend player and make your own method to play sound X times.
For that you can play this sound without repeat mode X times in a row. To detect that sound has finished playback check for MPMusicPlayerControllerPlaybackStateDidChangeNotification and beginGeneratingPlaybackNotifications. Based on that you play it again and again and decrease a count for how much times you want to play it.
I have an app that shows list of movies in a table view. When I play them one after another on device it works just great. But when I switch to Apple TV over AirPlay it doesn't work anymore. It play's the first video on ATV ok but after a switch to the next video the screen on ATV start blinking/flickering and after a few seconds it falls back playing on a device. I am using MPMoviePlayerController for playing stream videos.
I also found out that if previous video finished playing over AirPlay it tries to start the next one over AirPlay also. Is this intended behaviour?
Is this kind a related with property allowsAirPlay?
I think I've found a solution. Before you switch playing another video you should stop the previous one:
[self.moviePlayer stop];
This is not needed if you are not playing via AirPlay cos the next video will automatically stop previous one by nature - you can not play two videos at once.
But If you do play video over AirPlay you need to stop previous one first and than play the next one.
This solution works for me.
I was reading the AVPlayer class documentation and I couldn't find the answer for my question.
I'm playing a streamed audio from the Internet on my iPhone app and I'd like to know if after a [myAVPlayer pause]; invocation myAVPlayer will keep downloading the audio file on the background for a long time.
If the user pushes the "Pause" button, invoking [myAVPlayer pause]; and then leaves the app, will myAVPlayer keep downloading a large amount of data?
I'm concerned about this when the user is on 3G Network.
I am faced with the same question and have done some experimentation. My observations are only valid for video, but if they are also valid for audio, then AVPlayer will try to buffer around 30s of content when you press pause. If you have access to the webserver, you could run tcpdump/wireshark and see how long after you press pause that the server continues to send data.
You can manage how long AVPlayer continues to buffer.
You need to manage preferredForwardBufferDuration of avplayer currentItem. If you want to stop buffering set value to 1 because if you set it to 0 it will be set up automatically
self.avPlayer.currentItem.preferredForwardBufferDuration = 1;
From Apple documentation: This property defines the preferred forward buffer duration in seconds. If set to 0, the player will choose an appropriate level of buffering for most use cases. Setting this property to a low value will increase the chance that playback will stall and re-buffer, while setting it to a high value will increase demand on system resources.
I have set up an AVAudioPlayer object in viewDidLoad, as per the Apple guidelines, calling prepareToPlay as the last line in viewDidLoad (i have tried in awakeFromNib also).
When i press my play button, there is a pause, as it would appear to load the file, then it plays.
In audioPlayerDidFinishPlaying, i reload the player with a different sound, and when clicking play for a second time, the file plays instantly.
What would cause the player to lag on the first play?
Thanks.
The delay is due to AVAudioPlayer being initialised. Please see this answer.
The audio system runs on several asynchronous software processes (audio units, OS drivers, etc.) and hardware systems (DMA, DACs, audio amp power supplies, etc.) that never really all completely finish initialization until some sound is actually played all the way out the speakers or earphones.
Here's one method to do that: Create a sound file containing a half second of silence. On app start up, while your app and view controller are still loading, use AVAudioPlayer to play this file of silence. Now when your view finishes loading, AVAudioPlayer should be ready to play subsequent non-silent sounds much faster, since some audio (silence) has already already gone all the way out to the speakers.
What kind of sound are you playing? Alerts, something longer? If alerts, I did go this way and it's much better with lags ...
create system sound with AudioServicesCreateSystemSoundID
play system sound with AudioServicesPlaySystemSound
dispose system sound with AudioServicesDisposeSystemSoundID
... you only need to store SystemSoundID for each sound you would like to play.
I have a few single hit sounds(small sound effects) which I want to play when a button is pressed. Should I declare the player and then initialize the sound to the player in the IBAction of the button if I want to play different sounds on different buttons?
Or is there a method to call which you specify the sound as you play it?
the [audioPlayer play] statement plays what is already initialized or added to the player. How can I setup the play and call it at different places with some predefined sound?
Thanks
There's a bit of delay whenever you start playing a sound even if it's already loaded and all you have to do is hit [audioPlayer play]
If you need to initialize it before you play it i'd imagine the delay would be much more noticeable.
I think i'd make a separate audio player for each sound and populate an array with them. Keep an eye out for memory low messages and unload the objects if necessary but i don't think it will require much overhead.