Developer Blog

Play Video Without Losing Your User With PlayInBackground()

Some of my favorite experiences on Boxee feature a “picture-in-application” display where the video that is playing is presented next to rich app functionality. To curb the corporate talk, I love it when I can work in an app without interrupting my viewing experience. From simple implementations like the videowindow control in eGuiders to the realtime conversation experience provided by Cliqset, offering your users the ability to interact with your application while they watch video is one of the great experiences the Boxee platform can create.

Up until now, maintaining application focus while playing a ListItem has been somewhat problematic. Developers who want to play a video, but also keep the focus of the user on the application have had to use some threading gymnastics in order to create the experience they want.

Fortunately, with Boxee’s latest release 0.9.21, developers now create that experience with one API call. PlayInBackground() is a new, appropriately titled method in Boxee’s Python API that works just like the tried and true Play() developers have come to know and love, with one big difference. Instead of directing the user to Boxee’s video player, the media is played “in the background” without changing the user’s focus in the application.

Just like Play(), PlayInBackground() accepts a ListItem object as an argument. Consider the following code in an onclick event for a list container with id “100.”

# Instantiate Player object
myPlayer = mc.Player()
 
# Retrieve ListItem object from list container
items = mc.GetActiveWindow().GetList(100).GetItems()
n = mc.GetActiveWindow().GetList(100).GetFocusedItem()
listitem = items[n]
 
# Play!
myPlayer.PlayInBackground( listitem )

The video can then be displayed to in your app with a simple videowindow control. This GUI control allows the developer to surface the playing video in his/her app with positioning and dimensioning just like an image control.

Consider the following XML:

<control type="videowindow">
	<posx>15</posx>
	<posy>207</posy>
	<width>520</width>
	<height>293</height>
</control>

And just like that, your app has “picture-in-application” support! The uses for this new method are bounded only by imagination, a resource I’ve learned is in abundant supply in this community. Enjoy!

April 30, 2010 at 8:48 pm