Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to handle back action in Chromecast with Google TV. #144

Open
alexballas opened this issue Nov 19, 2022 · 4 comments
Open

Comments

@alexballas
Copy link

Hello,
I've been trying to get the *cast.Media data when loading a file.
./go-chromecast load ~/Videos/video.mp4

I added this snippet

go func() {
	tik := time.NewTicker(time.Second)
	for range tik.C {
		_, m, _ := app.Status()
		fmt.Println("Media:", m)
	}
}()

here https://github.com/vishen/go-chromecast/blob/master/cmd/load.go#L66 just to test.
It returns

Media: <nil>
Media: <nil>
Media: <nil>

while the video plays fine.

Am I missing something? How does *cast.Media get populated?

I'm using a Chromecast with Google TV

@vishen
Copy link
Owner

vishen commented Nov 20, 2022

@alexballas at the moment you need to call app.Update() to populate the media: https://github.com/vishen/go-chromecast/blob/master/ui/update_status.go#L41-L45 This probably isn't the best API, but for now it is how it works.

@alexballas
Copy link
Author

alexballas commented Nov 20, 2022

Ah! thank you so much! One last question. Is it possible to "detect" when someone pressed the "back" button. When I load something and I click the back button, chromecast takes my back to the menu but status is still reporting as BUFFERING. The only indication that the file stopped playing is the app.PlayedItems()[media].Finished which is > 0 but even that, is not very consistent.

@vishen
Copy link
Owner

vishen commented Nov 21, 2022

Hmm, I don't think anything is exposed at the moment. There is a private field to track whether the media is playing or not https://github.com/vishen/go-chromecast/blob/master/application/application.go#L119 (although I am not 100% sure this works in all scenarios). Since this isn't currently exposed nicely, we could add a new field to track the last media status or the current status of the recently played media?

Does "polling" the status command show you anything useful when the "back" button is pushed?

One other thing to try is, go-chromecast watch which will show you all the chromecast commands being broadcast. There might be a BACK command that we aren't picking up yet that could be useful in this?

@alexballas alexballas changed the title Question: Getting the *cast.Media from the application Status() Question: How to handle back action in Chromecast with Google TV. Nov 21, 2022
@alexballas
Copy link
Author

alexballas commented Nov 22, 2022

Changed the issue title to better reflect what I'm after

So I did some investigation.
go-chromecast watch does not report anything about the "back" button press. It just changes the status from "PLAYING" to "BUFFERING". As a result, mediaFinished does not get triggered.

The only thing that indicated that the media has stopped playing is the app.PlayedItems()[media].Finished which is populated at the end of the web request. However, depending on the media file and size, Chromecast might trigger multiple HTTP calls with different byte range headers, so momentarily app.PlayedItems()[media].Finished might report 0 then something else then 0 again.

I don't want to keep this issue open if there is indeed no straight forward way to do it. Let me know if you have any other ideas on how to best approach this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants