Giter Club home page Giter Club logo

Comments (26)

cmoulikus avatar cmoulikus commented on May 5, 2024

I have a come long way, thanks to Michael. There was time when nothing was working for me. Now I am stuck on the last part: how to chrome cast what is dispalying on the client using the cleint.playMEdia(item) call.

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

This Reddit post doesn't make it sound promising for the Chromecast. -- I believe we would need it to show up in the clients list to even think about getting it to work.

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

Marking this as an enhancement. If the Plex Web Client and cast to a Chromecast, maybe we can add a new function to cast as well.

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

I just ordered a Chromecast, excited to make this one work. :P

from python-plexapi.

cmoulikus avatar cmoulikus commented on May 5, 2024

from python-plexapi.

Hellowlol avatar Hellowlol commented on May 5, 2024

https://github.com/balloob/pychromecast

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

Interesting. I was hoping we could add Chromecast support by calling some URL on the Plex Media Server, but that doesn't seem to be the case. When we connect to a Chromecast from the webapp, there is no ajax request sent anywhere, and it all seems to be handled via JS & Chrome Browser. This is also spit out in the logs, which may be useful:

{
"sessionId":"70f76413-f64e-4656-8f4e-43489c2766f3",
"appId":"9AC194DC",
"displayName":"Plex",
"statusText":"Plex",
"receiver":{
  "label":"rRckpLGcPLvz4_hkCyoxuFkBPANk.",
  "friendlyName":"Chromecast3683",
  "capabilities":["video_out","audio_out"],
  "volume":{
    "controlType":"attenuation",
    "level":1,
    "muted":false,
    "stepInterval":0.05000000074505806
  },
  "receiverType":"cast",
  "isActiveInput":null,
  "displayStatus":null
},
"senderApps":[],
"namespaces":[
  {"name":"urn:x-cast:com.google.cast.broadcast"},
  {"name":"urn:x-cast:com.google.cast.media"},
  {"name":"urn:x-cast:plex"}
],
"media":[],
"status":"connected",
"transportId":"70f76413-f64e-4656-8f4e-43489c2766f3"
}

Looking at pychromecast, it seems easy enough to cast. But I wonder what the usefulness is of us adding a function to do the very basic steps they have in their readme. It it worth the 4 extra dependancies just to add a castMedia() function which essentially will do the following:

import pychromecast

def castMedia(media, ccName):
    chromecasts = pychromecast.get_chromecasts()
    cast = next(cc for cc in chromecasts if cc.device.friendly_name == ccName)
    cast.wait()
    mc = cast.media_controller
    mc.play_media(media.parts[0].file, 'video/mp4')
    mc.block_until_active()
    return cast, mc

Perhaps the usefulness is auto-starting the next media file when there is more than one part or managing playlists?

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

Looks like some other people got this working..
https://forum.xda-developers.com/android-tv/chromecast/plex-python-chromecast-t3520651

from python-plexapi.

Hellowlol avatar Hellowlol commented on May 5, 2024

Can you make a official guide on how to make this work or does the example above work? I don't have chromecast. We could add it to the utility file with a inline import

from python-plexapi.

Hellowlol avatar Hellowlol commented on May 5, 2024

@pkkid Did you figure out how to cast somthing at chromecast?

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

I never ended up trying.

from python-plexapi.

Hellowlol avatar Hellowlol commented on May 5, 2024

I got this working. Ill post an example and create a PR later👍

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

from python-plexapi.

Hellowlol avatar Hellowlol commented on May 5, 2024

You can use this branch to test support for chromecast. https://github.com/pkkid/python-plexapi/tree/chromecast

pychromecast does have some deps and are 3.4 only so dunno if we should merge it.

from python-plexapi.

aazimh avatar aazimh commented on May 5, 2024

@Hellowlol just wanted to say I've been breaking my head over this for weeks and just stumbled on to this and managed to get your PR working - thank you so much!

from python-plexapi.

Hellowlol avatar Hellowlol commented on May 5, 2024

@aazimh your welcome. Thanks for testing it 🎉

from python-plexapi.

aazimh avatar aazimh commented on May 5, 2024

@Hellowlol Okay, on some further testing maybe things aren't all that perfect :) it appears to work fine if the Plex Chromecast app is already up and running - however, if something else is casting, or even if the Chromecast is idle, all I get is the Plex splash screen saying 'ready to play', but the media in question doesn't end up playing.

I've tried reading through your code to debug it, but don't think I can be much help. All I can think of is adding some sort of delay between launching the Plex app and actually sending the play media command? I tried doing this myself but it looks like the 'play_media' command is what actually launches the app so not possible to add a delay anywhere.

Hope this is useful information for debugging!

from python-plexapi.

aazimh avatar aazimh commented on May 5, 2024

This is my code - selection is the result of a search, and cast is my Chromecast (these assignments have been made already):

cast.wait()
pc = PlexController()
cast.register_handler(pc)
cast.wait()
pc.play_media(selection)

I know I have an extra wait() since I thought that might help the Chromecast get ready to receive the play command, but it doesn't seem to make a difference.

from python-plexapi.

Hellowlol avatar Hellowlol commented on May 5, 2024

My example don’t handle this. That up the user. You can check if the current running app is plex, if not you can launch the app manually then do the play_media. I thought chromecast should handle the running app. Have try tried enabling som logging so you see what happens?

from python-plexapi.

Hellowlol avatar Hellowlol commented on May 5, 2024

I’m only on mobile atm but is seems like it it’s a bug in the pychomecast send_message, the call_back isn’t used.

from python-plexapi.

aazimh avatar aazimh commented on May 5, 2024

So I had some time to dig into this today and I think I have a hacky solution. I used your tip of checking the current app - if it is Plex already, I just use play_media normally. If not, then I start the app manually, wait 5 seconds (seems to be enough time for it to become ready) and then play_media and it works :) code below in case it helps:

		if cast.status.display_name == 'Plex':
			pc = PlexController()
			cast.register_handler(pc)
			pc.play_media(selection)
		else:
			cast.start_app('9AC194DC')
			pc = PlexController()
			cast.register_handler(pc)
			cast.wait()
			time.sleep(5)
			pc.play_media(selection)

I know you mentioned it being a bug in pychromecast not using a callback, and I tried looking into that but it went over my head :) if you're able to crack that I'd be more than happy to test out.

from python-plexapi.

pkkid avatar pkkid commented on May 5, 2024

If you ask for the cast.status.display_name in a loop, will it eventually say 'Plex' when it's ready?

from python-plexapi.

aazimh avatar aazimh commented on May 5, 2024

@pkkid Great suggestion :) it's definitely ready in less than 5 seconds so this works a lot better! Code below, but if there's a better way to loop let me know - thanks again for the tip!

		if cast.status.display_name == 'Plex':
			pc = PlexController()
			cast.register_handler(pc)
			pc.play_media(selection)
		else:
			cast.start_app('9AC194DC')
			pc = PlexController()
			cast.register_handler(pc)
			current_app = cast.status.display_name
			while current_app != 'Plex':
				current_app = cast.status.display_name
				time.sleep(1)
			pc.play_media(selection)

from python-plexapi.

Hellowlol avatar Hellowlol commented on May 5, 2024

I’m sure there is a better way to do this. I’ll looking into it when I try to recreate the launch issue.

from python-plexapi.

Hellowlol avatar Hellowlol commented on May 5, 2024

I have updated the branch with a new method called block_until_playing use this one if you want to ensure that the your program does not exit until the callback is done.

from python-plexapi.

Hellowlol avatar Hellowlol commented on May 5, 2024

Closing this a my PR was merged in pychromecast

from python-plexapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.