In which cases avplayer should play? Like play() function, set player rate - ios

I set player to pause and i am setting player rate after the pause. After setting player rate avplayer starting the playing without play() method, so i want to know in which other cases that avplayer should play without play() method.
I find that when we set rate or seek to specific time than it is play but i want to know is there other cases when avplayer should play.

Please check https://github.com/teamSolutionAnalysts/sa-plug-avplayer which is very easy plug and play module, lets you play video easily and you tube embedded url supported.

Related

How to sync custom audio with video in iOS?

I am trying to make a video player with custom audio effects. To perform an effect I've written an audio unit. To play video stream I use AVPlayer with muted sound. The problem is that audio and video are out of sync. And it gets awful when I pause and resume the playback.
Could you please suggest any ideas about how to sync the two things? Maybe use something else instead of AVPlayer?
Thanks in advance.
I shall answer my own question.
There is a thing called MTAudioProcessingTap. It allows for doing audio manipulation stuff just like an audio unit but inside AVPlayer.
There's a link for more details: https://chritto.wordpress.com/2013/01/07/processing-avplayers-audio-with-mtaudioprocessingtap/.=

Swift - Playing Audio file and Itunes Music simultaneously

I am currently building a game with swift and spritekit. I want to play a sound in a certain part of the code. Currently I am using AVAudioPlayer. I am currently using this method.
player = try AVAudioPlayer(contentsOfURL: url)
player.prepareToPlay()
player.play()
The sound plays correctly, but if I were to be listening to music through itunes while the sound is played my itunes music is stopped and the sound is played. I have played other people's games in the past where ingame sound effects play and do not effect music that was already playing from another app. Can somone explain how this is achieved.Thanks a bunch.
You'll need to set your audio session to use a category that allows mixing. By default it uses AVAudioSessionCategorySoloAmbient which is non mixable.
I don't know which category will fit your needs but AVAudioSessionCategoryAmbient allows mixing.
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient)

Play Song at specific index of MPMediaItemCollection in Swift

I try to make my own Musicplayer with Swift. I need to jump to a specific song/index of my MPMediaItemCollection and start to play it but i can only find methods like skipToNextItem() and skipToPreviousItem(). Is there any other way to do that than with a loop?
let player = MPMusicPlayerController.systemMusicPlayer()
player.setQueueWithItemCollection(mediaCollection)
player.play()
According to the documentation, we use the nowPlayingItem property.
To specify that playback should begin at a particular media item in the playback queue, set this property to that item while the music player is stopped or paused.
So, it sounds like you should stop or pause the player, set the nowPlayingItem, and then call play again.
player.nowPlayingItem = mediaCollection.items[selectedIndex]
player.play()

volume slider has no effect

I am creating a radio streaming app with play, pause and volume slider.
I have implemented volume slider using MPVolumeView but unfortunately it is not working.
Can any one please let me know the correct code so that the volume slider will work in my app. I have used MPMoviePlayerController, AVPlayer, AVAudioPlayer.
Sounds as if you missed an important part of Apple's documentation;
Working with Movies and iPod Music
I am suspecting that you are using both, AVAudioPlayer and MPMoviePlayerController together and that you have setup some audio session attributes to get that working properly. Now when doing so, you may want to tell MPMoviePlayerController to use that session / or not.
Using the Media Player Framework Exclusively
If your application is using a movie player only, or a music player
only—and you are not playing your own sounds—then you should not
configure an audio session.
If you are using a movie player exclusively, you must tell it to use
its own audio session, as follows:
myMoviePlayer.useApplicationAudioSession = NO
If you are using a movie
player and a music player, then you probably want to configure how the
two interact; for this, you must configure an audio session, even
though you are not playing application audio per se. Use the guidance
in Table 6-1.

Movie is played with some delay after calling play on MPMoviePlayerController

I am developing an iPhone application in which I play the videos using MPMoviePlayerController. Sometimes, some of the videos does not play immediately after I call play on MPMoviePlayerController.
I have called prepareToPlay and in the notified method of MPMediaPlaybackIsPreparedToPlayDidChangeNotification, I am calling play on MPMoviePlayerController.
How can I identify the problem here?
Try using the property movieSourceType and assign a proper value to it before running prepareToPlay.
From MPMoviePlayerController reference;
The default value of this
property is MPMovieSourceTypeUnknown.
This property provides a clue to the
playback system as to how it should
download and buffer the movie content.
If you know the source type of the
movie, setting the value of this
property before playback begins can
improve the load times for the movie
content. If you do not set the source
type explicitly before playback, the
movie player controller must gather
this information, which might delay
playback.

Resources