Skip to content

Commit

Permalink
Fixed sending commands on media channel after resuming session
Browse files Browse the repository at this point in the history
  • Loading branch information
Tapanila committed Jul 18, 2024
1 parent e7a8117 commit 26de60e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Sharpcaster.Test/MediaChannelTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,34 @@ public async Task TestFailingLoadMedia(ChromecastReceiver receiver)

}

[Theory]
[MemberData(nameof(ChromecastReceiversFilter.GetChromecastUltra), MemberType = typeof(ChromecastReceiversFilter))]
public async Task TestJoiningRunningMediaSessionAndPausingMedia(ChromecastReceiver receiver)
{
var TestHelper = new TestHelper();
ChromecastClient client = await TestHelper.CreateConnectAndLoadAppClient(output, receiver);
AutoResetEvent _autoResetEvent = new AutoResetEvent(false);
MediaStatus mediaStatus;

var media = new Media
{
ContentUrl = "https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/mp4/DesigningForGoogleCast.mp4"
};

mediaStatus = await client.GetChannel<IMediaChannel>().LoadAsync(media);
await client.GetChannel<IMediaChannel>().PlayAsync();

client = TestHelper.GetClientWithTestOutput(output);
var status = await client.ConnectChromecast(receiver);

var applicationRunning = status.Applications[0];



var chromecastStatus = await client.LaunchApplicationAsync(applicationRunning.AppId, true);
await client.GetChannel<IMediaChannel>().PauseAsync();
}

}

}
6 changes: 6 additions & 0 deletions Sharpcaster/Channels/MediaChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,11 @@ public async Task<int[]> QueueGetItemIdsAsync(long mediaSessionId)
return (await SendAsync<QueueItemIdsMessage>(new QueueGetItemIdsMessage() { MediaSessionId = mediaSessionId }, chromecastStatus.Applications[0].TransportId)).Ids;
}

public async Task<MediaStatus> GetMediaStatusAsync()
{
var chromecastStatus = Client.GetChromecastStatus();
return await SendAsync(new Messages.Receiver.GetStatusMessage(), chromecastStatus.Applications[0]);
}

}
}
6 changes: 6 additions & 0 deletions Sharpcaster/ChromeCastClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@ public async Task<ChromecastStatus> LaunchApplicationAsync(string applicationId,
if (runningApplication != null)
{
await GetChannel<IConnectionChannel>().ConnectAsync(runningApplication.TransportId);
//Check if the application is using the media namespace
//If so go and get the media status
if (runningApplication.Namespaces.Where(ns => ns.Name == "urn:x-cast:com.google.cast.media") != null)
{
await GetChannel<IMediaChannel>().GetMediaStatusAsync();
}
return await GetChannel<IReceiverChannel>().GetChromecastStatusAsync();
} else {
// another AppId is running
Expand Down
1 change: 1 addition & 0 deletions Sharpcaster/Interfaces/IMediaChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ public interface IMediaChannel : IStatusChannel<IEnumerable<MediaStatus>>, IChro
Task<MediaStatus> QueuePrevAsync(long mediaSessionId);
Task<QueueItem[]> QueueGetItemsAsync(long mediaSessionId, int[] ids = null);
Task<int[]> QueueGetItemIdsAsync(long mediaSessionId);
Task<MediaStatus> GetMediaStatusAsync();
}
}

0 comments on commit 26de60e

Please sign in to comment.