Deezer Javascript SDK playAlbum offset ignored on mobile

74 views Asked by At

In my Deezer InApp, when I call the DZ.player.playAlbum method with a non-zero offset, e.g. DZ.player.playAlbum(10008268, true, 0, 13), the playback starts at the given offset on the Deezer desktop site, but in the mobile apps (both Android and iOS) the playback starts from the beginning. Is the offset not supported on mobile? Is there any workaround solution? This would be an important feature for me to have.

1

There are 1 answers

6
peruukki On

I found a workaround based on DZ.player.seek that seems to work on Android, but it won't work on iOS until receiving player_position events works on iOS:

const album = 10008268;
const trackIndex = 0;
const offset = 10;

DZ.player.playAlbum(album, true, trackIndex, tracklist => {
  if (offset) {
    DZ.Event.subscribe('player_position', args => {
      const position = args ? args[0] : null;
      if (position) {
        const currentTrack = tracklist.tracks[trackIndex];
        const currentTrackLength = Number(currentTrack.duration);
        const seekOffset = offset / currentTrackLength * 100;
        DZ.player.seek(seekOffset);

        setTimeout(() => DZ.Event.unsubscribe('player_position'));
      }
    });
  }
});

Listening for player_position events is needed because calling DZ.player.seek seems to have no effect if the player position is 0. Also, I need to use setTimeout for unsubscribing outside of the callback function, otherwise I get an exception.