6

How can I listen to progress on Google Cast in iOS? I have implemented cast support in my app based on https://github.com/googlecast/CastVideos-ios but I don't want to use their GCKUIExpandedMediaControlsViewController class to control playback.

I added GCKRemoteMediaClientListener to GCKCastSession's GCKRemoteMediaClient. It calls

public func remoteMediaClient(_ client: GCKRemoteMediaClient, didUpdate mediaStatus: GCKMediaStatus?) {
        print("position: \(mediaStatus?.streamPosition)")
    }

But it's called every 10 seconds and I would like to get progress every second. Is there some way to do it? Or I have to implement my own timer and check current stream position every second?

Thanks

Martin Vandzura
  • 3,047
  • 1
  • 31
  • 63
  • Hi @vandzi. I tried the solution you suggested by creating a timer which inspects the media streamPosition. But the property `self.mediaClient?.mediaStatus?.streamPosition` is only updated when didUpdate is called, so reading this property every second has no effect. Did you succeed to get a better refresh rate? – Martin Apr 15 '20 at 13:02
  • @Martin I use this var playPosition = self.castMediaController.lastKnownStreamPosition – Martin Vandzura Apr 15 '20 at 13:05
  • Thanks vandzi. For your information, I also found the method: `mediaClient.approximateStreamPosition()` which estimate the stream position between two status updates. – Martin Apr 15 '20 at 14:47

2 Answers2

1

Same as your problem. After trying to find the solution for that issue, I use GCKUIMediaController to handle the progress timer.

_mediaController = [[GCKUIMediaController alloc] init];
_mediaController.playPauseToggleButton = _playButton;

_mediaController.nextButton = _nextButton;
_mediaController.previousButton = _previousButton;
_mediaController.streamPositionSlider = _timeSlider;
_mediaController.streamPositionLabel = _playedTimeLabel;
_mediaController.streamDurationLabel = _durationTimeLabel;
_mediaController.delegate = self;

Snip code above is an example I think can help you, I have used it for my project.

Quang Dam
  • 305
  • 3
  • 15
  • I'm having a problem here, the streamPositionLabel and streamDurationLabel are working as expected, but streamPositionSlider is not, it is loading half the real duration of the video, do you have any idea of why this could be happening? – Jalil Nov 16 '21 at 21:39
  • Hi @Jalil, following the [documents](https://developers.google.com/cast/docs/reference/ios/interface_g_c_k_u_i_media_controller#a966dcdf42029ef49fa45c207719f3080), maybe you can't do anything with it, I guess the problem comes from the wifi connection because your app and the receiver (Chromecast) communicate through wifi, sometimes the connection is not good and issues will happen. – Quang Dam Nov 18 '21 at 10:37
-4

It is recommended that you use the widgets provided by the SDK. They have been optimized to manage the media status efficiently. There are various ways you can customize and brand these widgets for your app.

Leon Nicholls
  • 4,623
  • 2
  • 16
  • 17
  • thanks, but that's not solution for me. I solved it by running timer every second and getting progress – Martin Vandzura Nov 14 '18 at 08:24
  • For performance reasons, we would not recommend your approach. – Leon Nicholls Nov 15 '18 at 16:53
  • 2
    So how it should be done if I can't use widgets provided by sdk? Is there somewhere widgets source code? I saw that widgets are showing time, so how they do it if not pulling every second? Is there some listener? – Martin Vandzura Nov 16 '18 at 12:22
  • 1
    @LeonNicholls as of Google engineer, could you please answer vandzi comment? Event to say something like "not possible"? – Martin Apr 15 '20 at 12:47