I’m trying to get my android app to send a Video URL by http POST to the launch params. I’m using connectSDK as the android app. Could anyone help out on how this works, and if using the launch params sample I have would work with this. I’ve looked at Roku’s DIAL documentation but I still cannot figure it out.
This is the roku app i’ve running for the launch parameters
sub Main(launchParameters)
' don't do anything unless we got a url
if launchParameters.url <> invalid
' setup a poster screen and assign it a message port
port = CreateObject("roMessagePort")
screen = CreateObject("roVideoScreen")
screen.SetMessagePort(port)
' build a content-meta-data using the passed in URL
screen.SetContent({
stream: { url: launchParameters.url }
})
screen.SetPositionNotificationPeriod(1)
'screen.SetContent({
' stream: { url: launchParameters.url }
' })
msg = Wait(10000, port)
' play the video
'waitMess = print "Waiting for video..."
screen.Show()
end
end sub
Do I even need the parameters? All I want is the video to send and play, could I leave all that out like this?
I’m not sure what way the video url should look like, on roku website they have the url looking like the way I have it but thats through the terminal, Should I be taking out the %2F’s?
Since you’ve added the Roku side of your code I can see that it won’t work. You should look at the SimpleVideoPlayer sample in the SDK for some working brightscript video playback. You need to be calling Show() before you loop on Wait().
I recommend hard-coding your URL within the Roku channel code until you have it successfully playing. After that you can try adding the DIAL remote launching.
I’m not sure about the Java thing you’re using, but here’s a working example in C# (error-checking omitted for clarity):
using System.Net;
using System.Web;
class Program
{
static void Main()
{
string rokuIp = "192.168.0.6";
string channelId = "dev";
string videoUrl = "http://video.ted.com/talks/podcast/DavidBrooks_2011.mp4";
// Note that the query string parameters should be url-encoded
string requestUrl = $"http://{rokuIp}:8060/launch/{channelId}?url={HttpUtility.UrlEncode(videoUrl)}";
using (var wc = new WebClient())
{
// POST the query string with no data
wc.UploadString(requestUrl, "");
}
}
}
and the BrightScript code:
Sub Main(params)
' Url to play if no launch parameters specified
urlParam = ""
' Check that launch parameters are specified
If Type(params) = "roAssociativeArray"
' Extract the url (if specified) from the launch parameters
If params.url <> Invalid
urlParam = params.url
End If
End If
' Play the video
port = CreateObject("roMessagePort")
ui = CreateObject ("roVideoScreen")
ui.SetMessagePort(port)
ui.SetContent ({Stream: {Url: urlParam, Bitrate: 0, Quality: False}})
ui.Show ()
While True
msg = Wait (0, port)
If Type (msg) = "roVideoScreenEvent"
If msg.IsScreenClosed ()
Exit While
End If
End If
End While
End Sub
Note that the query string parameters should be url-encoded in the client, but automatically appear in their decoded form when received by your Roku channel.
Here’s the Wireshark trace:
POST /launch/dev?url=http%3a%2f%2fvideo.ted.com%2ftalk%2fpodcast%2f2016%2fNone%2fMoranCerf_2016.mp4 HTTP/1.1
Host: 192.168.0.6:8060
Content-Length: 0
Connection: Keep-Alive
HTTP/1.1 200 OK
Server: Roku UPnP/1.0 MiniUPnPd/1.4
Content-Length: 0
Thanks a lot for your BrightScript that i’m now using & the tip about the encoding . I still can’t manage to get it to work, I feel like its something simple i’m missing out on but can’t figure it out. Googling it looks like i’ve pretty much what I need for it to work but not sure whats wrong
public void postVideoURL() throws IOException {
String encodedUrl = URLEncoder.encode("http://video.ted.com/talks/podcast/DavidBrooks_2011.mp4", "UTF-8");
URL obj = new URL("http://10.50.0.105:8060/launch/dev?url="+encodedUrl);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
//add request header
con.setRequestMethod("POST");
// Send post request
con.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
System.out.println(con.getResponseCode());
System.out.println(con.getResponseMessage());
wr.flush();
wr.close();
wr.write("");
}