I would like to display info and skip the current song being played by the iPhone. I understand MPMusicPlayerController can do this for apple music. However, I would like to display and skip the current song if it is being played by a third-party app like Spotify or Audible.
let audioPlayer = MPMusicPlayerController.systemMusicPlayer
next song
audioPlayer.skipToNextItem()
previous song
audioPlayer.skipToPreviousItem()
Related
I am trying to detect which music from another app is playing in background.
I know there is a way to detect if a music is played in background but I would like to detect which song and the time if I can. How do I do that? In Swift or Objective-c
You can use the MediaPlayer framework to get the current Music playing in the Music app:
import MediaPlayer
let player = MPMusicPlayerController.systemMusicPlayer()
let currentSongTitle = player.nowPlayingItem?.title
let currentPlaybackTime = player.currentPlaybackTime
Note that you need to have the NSAppleMusicUsageDescription (aka Privacy - Media Library Usage Description) set to the String you want to present to the user when asking for permission.
i want to play songs in background without click for next song , songs will change in background and play next song in background .i search this link for play song in background : http://mobile.tutsplus.com/tutorials/iphone/ios-sdk_background-audio/
but from this link only we play one song in background . but i required play multiple songs in background like as music player .
is there any way to play multiple songs in background please suggest me
If you want to know when the song has finished to play you should use AVAudioPlayer Delegate!
When the song finishes to play you can change to the next song in method:
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
In this method you should remove your current player and init new player with new song.
I am creating an app that has a playlist and uses the MediaPlayer library. When a song ends I don't want the next song to start. I tried to use the MPMusicPlayerControllerNowPlayingItemDidChangeNotification to pause the music player when the song changes, but the song starts to play before I get the chance to stop it. I also tried to use KVO to track the changes to musicPlayer.currentPlaybackTime, but I only receive messages when i manually change the playback time. I can't find any information about this problem anywhere.
In my app I have shuffle and repeat off, and create a queue with only one song in it, then send that to the music player. When the song finishes, there aren't any other songs in the queue, so it stops playing.
That being said, the latest iOS update has stopped reporting the correct playback state when the song finishes and is reporting it as paused when it used to be stopped. Not sure if that's a side-effect of the above method or not.
Are you calling:
player.beginGeneratingPlaybackNotifications()
before adding the observers?
I have implement an application.In which there is list of videos.when user touch on the video then video play in MPMoviePlayer.But when video is finished then i want to play another video automatically.Is it possible?
Yes. Do you want it to play another one randomly? You could do that. Or do you have an NSArray that contains all the different MPMoviePlayer URLs to play in order? If you do, then loop through the array objects and play each. You will have to have a MPMoviePlayerPlaybackDidFinishNotification to know when each videos finish so you can start the next one.
i need to play songs from my music library in the background , while playing video..
Both audio and video will play at the same time... first i tried using mpmusicplayercontroller to play music , but when i play video , its stops playing song in background. after that i tried to play music using audiotoolbox."Audio Queues". now i can play audio and video at the same time ,but the song i am playing is static. i want to play song from ipod library and i need to provide the file path there, so is there any way to get the library song path? or any other idea? please suggest..!
While it may be possible, Apple doesn't want you to know how. They don't want people to be able to programmatically access the song data. It can lead to music sharing, which Apple tries not to make easy.
Maybe the way to do this is to have your videos be the thing that is static and get your songs through MPMusicPlayer. Of course, you'll have to play them with a different mechanism than MPMediaPlayer.