jeremyk
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2012
10:03 AM
Hit a simple URL with code?
I just need to hit a simple URL prior to displaying content, but I don't want to hold up the video from playing (in case it doesn't return). The plan is obviously to use this for a simple analytics event, but just not sure of a simple way to do it.
Thanks for the help.
Thanks for the help.
6 REPLIES 6
agmark
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2012
10:30 AM
Re: Hit a simple URL with code?
belltown posted a very good routine to check the response code from a url. It could be easily adapted for your use.
http://forums.roku.com/viewtopic.php?f=34&t=47659&start=30#p327128
http://forums.roku.com/viewtopic.php?f=34&t=47659&start=30#p327128
belltown
Roku Guru
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2012
10:47 AM
Re: Hit a simple URL with code?
"agmark" wrote:
belltown posted a very good routine to check the response code from a url. It could be easily adapted for your use.
http://forums.roku.com/viewtopic.php?f=34&t=47659&start=30#p327128
That function should do what you want. It sends an request to a url asynchronously. When you call it pass in a timeout value (in milliseconds) instead of zero (wait forever).
jeremyk
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2012
10:50 AM
Re: Hit a simple URL with code?
Yup, this is perfect. Thanks for the quick response!

RokuJoel
Binge Watcher
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2012
10:52 AM
Re: Hit a simple URL with code?
Create an RoURLTransfer object, and set it's port to the same port as your videoscreen. Give your wait statement a time like 100 milliseconds instead of 0. Add a check for the returned value, for example:
here is the URL Transfer setup:
then the while loop with a non-zero wait time (here, i've set it to 100 milliseconds), and I've made it the first message-type check:
This way, you can have multiple things going on - video is playing and, you are also checking for a URL Event.
- Joel
Function showVideoScreen(episode As Object)
if type(episode) <> "roAssociativeArray" then
print "invalid data passed to showVideoScreen"
return -1
endif
port = CreateObject("roMessagePort")
screen = CreateObject("roVideoScreen")
screen.SetMessagePort(port)
screen.SetPositionNotificationPeriod(30)
screen.SetContent(episode)
here is the URL Transfer setup:
xfer=createobject("roURLTransfer")
xfer.seturl("http://myserver.com/check.php")
xfer.setport(port)
xfer.asyncgettostring()
screen.Show()
'Uncomment his line to dump the contents of the episode to be played
'PrintAA(episode)
then the while loop with a non-zero wait time (here, i've set it to 100 milliseconds), and I've made it the first message-type check:
while true
msg = wait(100, port)
if type(msg)="roUrlEvent" then
str=msg.getstring()
print "************returned url data************"
print str
else if type(msg) = "roVideoScreenEvent" then
?"******************************************MESSAGE**********************************"
?"message:";msg.getmessage();" Type:";msg.gettype();" Index:"; msg.getindex();" data:";msg.getdata();" playback pos? ";msg.isplaybackposition()
?"******************************************MESSAGE**********************************"
'print "showHomeScreen | msg = "; msg.getMessage() " | index = "; msg.GetIndex()
if msg.isScreenClosed()
print "Screen closed"
exit while
elseif msg.isRequestFailed()
print "Video request failure: "; msg.GetIndex(); " " msg.GetData()
elseif msg.isStatusMessage()
print "Video status: "; msg.GetIndex(); " " msg.GetData()
elseif msg.isButtonPressed()
print "Button pressed: "; msg.GetIndex(); " " msg.GetData()
elseif msg.isPlaybackPosition() then
nowpos = msg.GetIndex()
RegWrite(episode.ContentId, nowpos.toStr())
else if msg.isStatusMessage() then
?"status message"
?"message:";msg.getmessage();" Type:";msg.gettype();" Index:"; msg.getindex();" data:";msg.getdata()
else if msg.isstreamstarted() then
?"StreamStarted"
?"message:";msg.getmessage();" Type:";msg.gettype();" Index:"; msg.getindex();" data:";msg.getdata()
else
print "Unexpected event type: "; msg.GetType()
end if
end if
end while
End Function
This way, you can have multiple things going on - video is playing and, you are also checking for a URL Event.
- Joel
jvalero
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2012
11:38 AM
Re: Hit a simple URL with code?
I'm trying to check that my URL transfers are working as well, and this post was very helpful in understanding the proper approach to do so. However, my scenario is slightly different in that I want to both call a URL at the beginning of playback, but also at certain increments of progress as well. Simply put, I need to call some impression URLs before the video starts, and then I also need to call some additional progress related urls at for example 25%, 50%, 75%, completion.
To handle the progress side of things I've setup some code to fire off as the playback position reaches a certain milestone.
Here is a stripped down version of this part of my loop:
I create the vastProgressUrl right before the overall event loop for the port:
And I have the following in my event loop:
msg = wait(100, messagePort)
'// URL Transfer Events
For some reason I'm not seeing anything back from this pass or fail. So I'm wondering if it is an issue with the loop and me making the URL requests inside of it. Any ideas?
To handle the progress side of things I've setup some code to fire off as the playback position reaches a certain milestone.
Here is a stripped down version of this part of my loop:
If marker = "midpoint" And Int((m.position / m.duration) * 100) > 49 And m.vastMp = False
PrettyPrint("Called Midpoint Url: " + url) '// PrettyPrint() = Custom function to print out formatted debug info.
vastProgressUrl.SetUrl(url)
vastProgressUrl.AsyncGetToString()
m.vastMp = True '// This just makes sure that each milestone is printed once
End If
I create the vastProgressUrl right before the overall event loop for the port:
vastProgressUrl = CreateObject("roUrlTransfer")
vastProgressUrl.SetPort(messagePort)
And I have the following in my event loop:
msg = wait(100, messagePort)
'// URL Transfer Events
If Type(msg) = "roUrlEvent" Then
'// And if response code == OK
If msg.GetResponseCode() = 200 Then
'// Assign Response
Print "Success: " msg.GetResponseCode()
Else
Print "Failed response. Reponse Code: " + msg.GetResponseCode()
End If
End If
For some reason I'm not seeing anything back from this pass or fail. So I'm wondering if it is an issue with the loop and me making the URL requests inside of it. Any ideas?
jvalero
Visitor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2012
02:25 PM
Re: Hit a simple URL with code?
I managed to figure it out. I had to setup another port to listen in on the url events. I'm now getting back success and fail messages.