Is there a way to get information about the previous iPod song? - iphone

I'm trying to store the playhead time of a song (MPMediaItem) before the next song begins to play. How would you do that?
Is there something like MPMusicPlayerControllerNowPlayingItemDidChangeNotification which fires before the song changes?

Simple: When the song changes, set a variable foo somewhere to the current time, and set another variable bar to the new song's current playback time (usually gonna be 0.0.) When the song changes again, subtract the value of foo from the current time, then add the value of bar; the result is the final offset of the song that was just being played.
You'll also have to handle fast forward, rewind, stop, and pause, but you can do that by monitoring the playback state and querying the song's current playback time to keep yourself in sync as needed.

I do'nt think, there is such notification(Notify before song change) exist today.
I just find only two notification which can be listen for songs change state.
MPMusicPlayerControllerNowPlayingItemDidChangeNotification,
MPMusicPlayerControllerPlaybackStateDidChangeNotification,
Apple Documentation:
http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMusicPlayerController_ClassReference/Reference/Reference.html

I think there is no notification before media item is changed. The best way seems to use a timer to constantly copying the value from media player to a variable to store NSTimeInterval, until media item is changed or media player state is changed.

Related

Flutter Implementing pause and play..... Streaming Music

I've tried multiple flutter plug-ins to stream and play and pause music but as of currently, I haven't yet figured out a simple way to implement play and pause, whilst having the ability to avoid music overlapping, I want so that when the current song is playing, if I were to press play on new music track, the current song playing will stop and play the newly pressed song. I've tried flutter_sound, audio player, audio file player, and flute music player but I can't seem to figure out how to do this.
If it is possible either using one of these or a new plug-in, is there a way to implement what I have just described.
The library you seek is more of a multi-track player than a player. Which does not currently exists AFAIK.
The simplest way is to act according to the status of the tracks (which should be given by the player).
Roughly, what I suggest: have something that keeps the status (e.g. paused, playing, completed) of each track. (e.g. List of Tracks) When you press play on track 2 or track 1 finishes playing, you set to 'completed' (or as you wish) the track 1 and set to 'playing' the track 2.
Have a listener on the status of the current track and voila (for autoplay). When the track completes, notify the listener to call a function to start the next one on your list. When you press another track, set to 'completed' the current track and to 'playing' the track you pressed, then notify listeners.
Any library letting you know the status of a track is good enough for your purpose.

How to get Spotify iOS currently playing track

I'm using SPTAudioStreamingController.sharedInstance().metadata.currentTrack?.uri to get the currently playing track, but sometimes it returns the next song on the playlist, instead of what is playing right now.
Edit: I think it may have to do with the playlist it is playing from, since whenever I skip a track, it deletes from the playlist. Is there a way to play from the top song in the playlist every time a skip occurs?
Or even better: Is there a way to refresh a playlist?
You can use a delegate method and locally keep track of what track is playing:
func audioStreaming(_ audioStreaming: SPTAudioStreamingController!, didStartPlayingTrack trackUri: String!) {
self.currentURI = trackURI
}
Whenever a track starts playing, the delegate method will fire and you can locally store the current URI. Just make sure to also utilize the other delegate methods like didStopPlayingTrack in order to ensure you have all the correct information.

Methods DZ.player.getCurrentTrack() and DZ.player.getCurrentIndex() not working properly on Javascript SDK

I'm trying to get the current song every 500ms from the player so I can update my queue, however, when I use the DZ.player.addToQueue method it changes both currentIndex and currentTrack to the first song back again. While the player keeps on the right song without changing it, the index goes back to the first one until the current song ends.
The issue is fixed in the latest version; the index will not go back to the first song.

Prevent MPMusicPlayerController from playing next song in que

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?

Is it possible to play a video on iPhone and have a subtitles synchronized with it show up?

I want to add a "subtitles" to a video played in an iPhone app. I don't want those subtitles encoded into the video itself - ideally I'd love to have a view showing the video (with pause, play, volume and such standard controls) together with a view displaying the text that changes together with movie time changing.
If I drawn that, it's something like this,
So, basicly, I would need a way to get a method called when movie is playing, and then synchronize the text displayed on the label with the movie timing.
Anyone used a solution that was able to do it?
I've recently done something that syncs graphics to times in an audio track. The way I did it was by using the currentPlaybackTime property of the MPMediaPlayback interface (which the MoviePlayer controller should also conform to). This returns the seconds elapsed in the media, in a double (typedef'ed as NSTimeInterval). The actual synchronisation in my app was not done in notifications, as I couldn't find any resembling a "tick", but instead I created a timer, calling a function queried the currentPlaybackTime, and updated the graphics based on this.
In terms of your implementation, I would assume you have some kind of system for associating label text (subtitles) with a particular time. You could then compare the text's time range with the time returned from currentPlaybackTime to find the correct text to display.