Roku - Web API - playMedia

Hi,

I’m trying to start playback on my Roku using the Web API using the following:

http://<CLIENT IP>:<CLIENT PORT>/player/playback/playMedia?key=%2Flibrary%2Fmetadata%2F<MEDIA ID>&offset=0&X-Plex-Client-Identifier=<CLIENT ID>&machineIdentifier=<SERVER ID>&address=<SERVER IP>&port=<SERVER PORT>&protocol=http&path=http%3A%2F%2F<SERVER IP>%3A<SERVER PORT>%2Flibrary%2Fmetadata%2F<MEDIA ID>

It works perfectly for the iPhone if I change ‘Plex-Client-Identifier’ to ‘Plex-Target-Client-Identifier’, but I’ve not been able to get it to work on the Roku.

If I use ‘Plex-Client-Identifier’ on the Roku it returns 200: ‘Ignoring Duplicate Playback Event’ - I found a thread where @ljunkie says to apply commandID - which then returns 200 OK, but doesn’t actually do anything. If I use ‘Plex-Target-Client-Identifier’ I just get 200, and again doesn’t do anything.

I enabled Roku logs and can see it receives my request and tries to make subsequent requests to server which return unauthorised. I took those requests and applied my X-Plex-Token and found they return OK. Whether or not I include my token with the initial request to the Roku makes no difference.

Any ideas?

Thanks!

Server Version#: 1.19.3.2843
Player Version#: 6.5.4.6365?

You’ll want to include a token in the request as a param, otherwise the Roku will not know what user is attempting the playback. It does not simply use the token that’s logged into the Roku, but the user info it was passed (via a token) to make sure playback is tied to the user controlling it.

I recommend creating a play queue on the server via HTTP post:

https://your.server.ip:32400/playQueues
?type=video
&shuffle=1
&repeat=0
&continuous=1
&own=1
&uri=server://YOUR SERVER IDENTIFIER/com.plexapp.plugins.library/library/metadata/NUMERIC

Include these headers:

X-Plex-Token:YOUR-TOKEN
X-Plex-Client-Identifier:ANY-UNIQUE-STRING

You’ll get the following XML back:

<MediaContainer size="21" identifier="com.plexapp.plugins.library" mediaTagPrefix="/system/bundle/media/flags/" mediaTagVersion="1571294176" playQueueID="12532" playQueueSelectedItemID="407084" playQueueSelectedItemOffset="0" playQueueSelectedMetadataItemID="223524" playQueueShuffled="1" playQueueSourceURI="library://x/item/%2Flibrary%2Fmetadata%2F21937" playQueueTotalCount="280" playQueueVersion="1">

The two elements we need from this are playQueueID and playQueueSelectedMetadataItemID . The first identifies the queue, and the second identifies the first item to begin playing in the queue.

Get the Target-Client-Identifier of your Roku device from at http://your.server.ip:32400/clients?X-Plex-Token=YOUR-TOKEN-HERE (your Plex app needs to be open on the Roku)

Example:

<MediaContainer size="3">
<Server name="MacBook Pro" host="192.168.1.31" address="192.168.1.31" port="32433" machineIdentifier="IDENTIFIER" version="2.44.0.1018-8f77cbb9" protocol="plex" product="Plex Media Player" deviceClass="pc" protocolVersion="1" protocolCapabilities="navigation,playback,timeline,mirror,playqueues"/>
<Server name="Living Room Roku" host="192.168.1.36" address="192.168.1.36" port="8324" machineIdentifier="IDENTIFIER" version="6.4.2.5956-3cf1a1b7e-Plex Preview" protocol="plex" product="Plex for Roku" deviceClass="stb" protocolVersion="1" protocolCapabilities="timeline,playback,navigation,playqueues"/>
<Server name="Safari" host="192.168.1.4" address="192.168.1.4" port="32400" machineIdentifier="IDENTIFIER" version="4.8.3" protocol="plex" product="Plex Web" deviceClass="pc" protocolVersion="3" protocolCapabilities="timeline,playback,navigation,mirror,playqueues"/>
</MediaContainer>

Then send the play queue to the Roku via HTTP get (I send it via the server in this example, because the server can relay the command to the client, and its IP is consistent):

http://your.server.ip:32400/player/playback/playMedia
?protocol=http
&address=your.server.ip
&port=32400
&containerKey=/playQueues/PLAY QUEUE ID
&key=/library/metadata/FIRST ITEM ID
&offset=0
&commandID=1
&type=video
&machineIdentifier=YOUR SERVER ID
&token=YOUR TOKEN

Include these headers:

X-Plex-Client-Identifier:ANY-UNIQUE-STRING
X-Plex-Target-Client-Identifier:IDENTIFIER-OF-THE-ROKU-DEVICE

Thank you for your help @ljunkie. Is X-Plex-Token the ‘token’ you’re referring to? If so, it’s my fault for mentioning only right at the end of my original post that I did try with this token, but with or without it made no difference. The HTTP request works fine when posting to my iPhone. Unless you’re referring to another token I’m omitting that’s required for the Roku?

@radiocolin - Thank you for taking the time to post play queue information! When I was scanning the logs I could see that was the approach taken by the Roku App. I will try it, but I wonder if you’re able to clarify a couple of points for me? (Though I totally appreciate you may not have the answers!)

This approach creates an orphan queue which we then assign to the Roku? What’s the life cycle of the queue? If I didn’t assign it would it eventually destroy? When I stop playback does it get destroyed? Just concerned about clean up processes that I might need to account for (or side effects to other players playing media simultaneously).

I also don’t understand the difference between client identifier vs target client identifier and further, why any unique string will do for the client identifier.

Finally, I’m curious about the purpose of the ‘OWN’ flag for creating the queue.

Thank you!

There’s no cleanup required for play queues. Nor is there any impact to other clients on the server. I don’t know their exact lifecycle, but it’s not long if left alone. You can’t create it and then send it to a client a few hours later.

I don’t know what the own flag does, and I haven’t been able to discern its purpose by flipping it. But it’s included in all the commands I sniffed so I include it.

Client identifier is the name of the sending client, which is you. So you get to name yourself whatever you want.

Target client identifier is the system identifier of the device you want to receive the command.

Thanks @radiocolin! I will give it try :grinning:

@ljunkie - I misunderstood what you were saying about ‘token’. I realise from radiocolin’s example that the key should literally be ‘token’ - with that change it works!

Regardless, I will try the queue approach and see if that takes too.

Thanks both!

1 Like

If I send the request directly to the Roku it works, but if I take your approach and send to the Roku via the server then the Roku Plex app crashes and I’m thrown back to the Roku home screen.

Looking at the log I thought I saw it had received the requested and ultimately ended up throwing a ‘EXIT_BRIGHTSCRIPT_CRASH’, but haven’t been able to recreate the log to capture.

There’s something it doesn’t like… I cast to the Roku from my laptop and checked the log but I couldn’t see anything significantly different from what you’ve posted - bar messing around a little bit more and studying the logs I’m not sure quite what the issue is. :pensive:

I just noticed this same behavior this morning, with a script I’ve not changed in months.

Looks like a possible regression on the client side. We’ll fix it, but for now, you should be able to send it directly to the Roku.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.