Skip to content

Commit

Permalink
Switching playbacks preserves context.
Browse files Browse the repository at this point in the history
  • Loading branch information
sahailee committed Nov 21, 2020
1 parent f7e82d5 commit 773c922
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions GTASpot/GTASpot/radio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ public SpotifyRadio()
}
defaultPlaylistId = config.GetValue<string>("Options", "DefaultPlaylist", "");
GuaranteeLogin();
Logger.Log("Volume: " + volume);
Logger.Log("Playlist: " + defaultPlaylistId);
if (obtainedSpotifyClient)
{
InitialSpotifyRequests();
Expand Down Expand Up @@ -318,50 +316,55 @@ private void SetupActiveDevicesMenu()
if (defaultPlaylistId.Length != 0)
{
request.ContextUri = "spotify:playlist:" + defaultPlaylistId;
Logger.Log("0");
}
else
{
request.Uris = SpotifyGetSavedTracks();
Logger.Log("0.1");
}
}
else
{
if(curr.Context == null && defaultPlaylistId.Length != 0)
if(curr.Context != null)
{
request.ContextUri = "spotify:playlist:" + defaultPlaylistId;
Logger.Log("1");
request.ContextUri = curr.Context.Uri;
if (curr.Item != null)
{
request.OffsetParam = new PlayerResumePlaybackRequest.Offset();
request.OffsetParam.Uri = ((FullTrack)curr.Item).Uri;
request.PositionMs = curr.ProgressMs;
}
}
else if(curr.Context == null)
else if(defaultPlaylistId.Length != 0)
{
request.Uris = SpotifyGetSavedTracks();
request.Uris[0] = ((FullTrack)curr.Item).Uri;
request.OffsetParam = new PlayerResumePlaybackRequest.Offset();
request.OffsetParam.Position = 0;
request.PositionMs = curr.ProgressMs;
Logger.Log("1.2");
request.ContextUri = "spotify:playlist:" + defaultPlaylistId;
}
else
else
{
request.ContextUri = curr.Context.Uri;
Logger.Log("1.3");
request.Uris = SpotifyGetSavedTracks();
if(curr.Item != null)
{
request.Uris[0] = ((FullTrack)curr.Item).Uri;
request.OffsetParam = new PlayerResumePlaybackRequest.Offset();
request.OffsetParam.Uri = request.Uris[0];
request.PositionMs = curr.ProgressMs;
}
}
}
try {
var task = spotify.Player.ResumePlayback(request);
task.Wait();
Logger.Log("2: " + isSpotifyRadio);
if(isSpotifyRadio)
if (isSpotifyRadio)
{
SpotifySetVolume(volume);
}
else
{
SpotifySetVolume(0);
}
Logger.Log("3");
modMenuPool.CloseAllMenus();
}
catch(AggregateException ex)
Expand Down Expand Up @@ -554,7 +557,6 @@ private void Unmute()
}
catch(NoActiveDeviceException)
{
Logger.Log("5!");
modMenuPool.CloseAllMenus();
activeDevices.Visible = true;
GTA.UI.Notification.Show("No active device found. Please set an active device using the menu");
Expand Down

0 comments on commit 773c922

Please sign in to comment.