Getting error on previous query : [Ensure that source is set with /playback/source before this operation. (SOURCE_NOT_SET)]

29 views Asked by At

I am trying something like this to set the current source and then retrieve previous track using the source (Confirming that currentPandoraStation has an id ):

self.setPandoraSource(sourceId: currentPandoraStation.id) { (status) in
                    guard status == true else { return }
                    self.skipToPreviousPandoraSource(trackViewModel: trackViewModel) { (track) in
                        self.doPlay(track, startPlayback: true, errorHandler: errorHandler)
                    }
                }

My SetSource query :

mutation SetSource($deviceUuid: String!, $sourceId: String!) {
    playback {
    setSource (deviceUuid: $deviceUuid, sourceId: $sourceId) {
        id
        type
        current {
            ... on TrackItem {
                index
                ..(other values fetched)
            }
        }
    }
  }
}

My previous query:

mutation SkipToPreviousTrack($deviceUuid: String!, $sourceId: String!, $index: Int!, $elapsedTime: Float!) {
  playback {
    previous(deviceUuid: $deviceUuid, sourceId: $sourceId, index: $index, elapsedTime: $elapsedTime) {
      status
      current {
        ... on TrackItem {
            track {
                ... on Track {
                    ...TrackDetails
                }
            }
        }
      }
    }
  }
}

Please let me know if I have not understood the implementation correctly. Thanks.

1

There are 1 answers

0
Matt Martin On

I would advise you to double-check your various code paths to make sure you are always setting the source BEFORE you do any other operations.

This error (and others) are documented on this page in the Pandora Developer Center. As noted in the documentation, the device UUID needs to be the same in both cases:

SOURCE_NOT_SET info from developer center

Also, note that the source may need to be set again if the user/listener has not done any playback recently. The session info, including current source, is cached for some period of time but we don't make guarantees about how long that time period is.

I'm not 100% sure what you're trying to do based on the code you posted. It looks to me like you are fetching the current track which should be fine, but since you have the word "previous" there it's also worth noting that listeners are not always allowed to play the previous track. Whether or not listeners can do this depends on several factors (listener subscription state, content rights, etc). Please use the values in the allowed interactions array to determine what options should be presented to the user. Here's some examples of how Pandora currently varies playback controls on our web client (note that this is using a Premium account; controls would look different for ad-supported or Plus tiers):

previous option displayed during album playback for Pandora Premium listener

station playback for Pandora Premium listener

Note that these screenshots are just here for illustrative purposes and should not be treated as the source of truth on what is allowed. The allowed interactions returned by the API should always be used as the source of truth to ensure that you are complying with current policies/practices. There's also a bit more info on when playing the previous track is allowed here.