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

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.

Related

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.

I want an mp3 file to be played when a button is pressed a certain amount of times in swift

I am working on a tap counter app and I need a sound to be played every thousand clicks but I could not figure out how to play it after multiple clicks in swift. If possible could someone please provide the code necessary to do so. It would be very helpful.
Set a variable as a counter = 0. Increment that counter (+= operator) every time the button is pressed. Also check to see if if counter == 1000, and if so, play MP3 and reset counter to zero.

iphone html 5 video - how to start from different time

What is the correct way to begin playback of a video from a specific time?
Currently, the approach we use is to check at an interval whether it's possible to seek via currentTime and then seek. The problem with this is, when the video fullscreen view pops up, it begins playback from the beginning for up to a second before seeking.
I've tried events such as onloadmetadata and canplay, but those seem to happen too early.
Added information:
It seems the very best I can do is to set a timer that tries to set currentTime repeatedly as soon as play() is called, however, this is not immediate enough. The video loads from the beginning, and after about a second, depending on the device, jumps. This is a problem for me as it provides an unsatisfactory experience to the user.
It seems like there can be no solution which does better, but I'm trying to see if there is either:
a) something clever/undocumented which I have missed which allows you to either seek before loading or otherwise indicate that the video needs to start not from 00:00 but from an arbitrary point
b) something clever which allows you to hide the video while it's playing and not display it until it has seeked (So you would see a longer delay on the phone before the fullscreen video window pops up, but it would start immediately where I need it to instead of seeking)
do something like this;
var video = document.getElementsById("video");
video.currentTime = starttimeoffset;
more Information can be found on this page dedicated to video time offset howtos
For desktop browser Chrome/Safari, you can append #t=starttimeoffsetinseconds to your video src url to make it start from certain position.
For iOS device, the best we can do is to listen for the timeupdated event, and do the seek in there. I guess this is the same as your original approach of using a timer.
-R

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 there a way to get information about the previous iPod song?

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.