Activate Window and Begin Playing
#1
I am attempting to use "ActivateWindow" (on a keypress) and would like the window to instantly begin the file located at /mnt/usb/video1.mp4. I've tried the sub commands of files, and videofiles but cannot get it to start the video. I can get notifications to display and other functions to work. What am I missing? Looked around the forums for a bit but couldn't find any solution.

BACKGROUND
I have setup a keypad to my pi running xbmc. Upon booting, xbmc begins a slideshow of pictures from a folder. The following keys operate perfectly (keyboard.xml).


<one>PlayMedia(/mnt/usb/video1.mp4)</one>
<two>Notification(KEYPRESS, you pressed 2!, 3)</two>
<three>SlideShow(/mnt/usb/slideshow)</three>

I want to be able to start the video (which I can currently do), then have the slideshow display immediately following the short video. Thank you for any help in advance. I'm sure I will make my way around the forums over the next few days as this is all new to me.
Reply
#2
Welcome to the XBMC forums.

ActivateWindow is used to display a window. To play a video, use PlayMedia as you've done in your example for mapping the "<one>" key.

To perform multiple tasks, as you've requested, you can write a Python script with the following content:
Code:
import xbmc
xbmc.executebuiltin( "PlayMedia(/mnt/usb/video1.mp4)" )
xbmc.executebuiltin( "SlideShow(/mnt/usb/slideshow)" )

You would then map a key to execute this script (named "the-script.py" in this example):
Code:
<three>RunScript(/path/to/your/script/the-script.py)</three>

Since you are likely running Linux on your RPi, you need to give your script file execute permission:
Code:
chmod +x /path/to/your/script/the-script.py
or, if the above command returns an error, try:
Code:
sudo chmod +x /path/to/your/script/the-script.py
Reply
#3
Appreciate the prompt response! The script does begin, but the way you had coded it it plays the slideshow with the audio from the video. I flipped them around and it played the video them defaulted back to the home screen. Any ideas? Thanks
Reply
#4
(2013-10-31, 04:13)freshsqueeze Wrote: Appreciate the prompt response! The script does begin, but the way you had coded it it plays the slideshow with the audio from the video. I flipped them around and it played the video them defaulted back to the home screen. Any ideas? Thanks

See here

Quote:... Normal call will be non-blocking - so it returns before the extraction has been finished. Now it's possible to call built-in functions blocking by doing:
Code:
xbmc.executebuiltin('XBMC.RunScript(Q:\Scripts\myscript.py)', True)

Edit: This won't work for you either. My guess is you'll need to play the video, then monitor the player status in a loop until the player has stopped. Though not sure how to obtain the player status using the xbmc module, you may need to use JSON for that.
Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
Reply
#5
@freshsqueeze:

The following should start the slide show only once the video has stopped playing:

Code:
import xbmc
import time

def PlayAndWait(mediafile):
  xbmc.executebuiltin("PlayMedia(%s)" % mediafile, True)
  while xbmc.Player().isPlaying():
    time.sleep(1.0)

PlayAndWait("/mnt/usb/video1.mp4")
xbmc.executebuiltin("SlideShow(/mnt/usb/slideshow)")

More xbmc module methods here (Gotham) and here (Frodo)
Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
Reply
#6
Maybe a simpler, though less elegant, solution is to hard-code the time delay based on the duration of video1.mp4. So, assuming video1.mp4 is 20 seconds long:
Code:
import xbmc, time
xbmc.executebuiltin( "PlayMedia(/mnt/usb/video1.mp4)" )
time.sleep(20)
xbmc.executebuiltin( "SlideShow(/mnt/usb/slideshow)" )
This will delay the start of the slideshow for 20 seconds, allowing the video to complete playing.
Reply
#7
Thanks. And thanks for the edit. I tried the script before I saw an edit and had no luck. I would like to use the play and wait if possible as I have a couple different videos in length and this will make it easier for us if we come out with new videos that are different in length.

I can confirm the time.sleep does work as I have just tried that. Hopefully I can use the play and wait.
Reply
#8
Sure, you've got a couple of options now, so use whichever suits your requirements better. Smile
Reply
#9
PlayAndWait works GREAT. And the time.sleep will work for another project I am working on. Thank you both for your help. You will be seeing me around the forums more often.
Reply
#10
@milhousevh

where did you get that code from? is that custom? i am interested in knowing how exactly it works and what the %s and other various commands do. i searched the forums and google but couldn't find much more information about it.
Reply
#11
That modulo (%) operation wasnt in the python crash course I took, but its really useful.

http://docs.python.org/2/library/stdtype...operations
Reply
#12
(2013-10-31, 09:09)freshsqueeze Wrote: @milhousevh

where did you get that code from? is that custom? i am interested in knowing how exactly it works and what the %s and other various commands do. i searched the forums and google but couldn't find much more information about it.

The % operator is used for string formatting. %s is a format specification for a string variable, the value of which is specified after the % so:
Code:
xbmc.executebuiltin("PlayMedia(%s)" % mediafile, True)

is saying replace %s with the value of mediafile.

There are many different format specifications, for example, %d is used for a decimal number. You can also specify formatting, eg. %05d would ensure that the printed number always contains at least 5 digits, with leading zeroes. You can read more about format specifiers in the Python documentation.

If you want to format multiple values, the values need to be passed in parentheses (ie. as a "tuple"):
Code:
print("Here's a decimal [%05d], and this is a fixed-width left-aligned string [%-30s]" % (123, "abc"))
>>> Here's a decimal [00123], and this is a fixed-width left-aligned string [abc                           ]
Texture Cache Maintenance Utility: Preload your texture cache for optimal UI performance. Remotely manage media libraries. Purge unused artwork to free up space. Find missing media. Configurable QA check to highlight metadata issues. Aid in diagnosis of library and cache related problems.
Reply
#13
thank you both. one more question for today. i would like a python script to look for a file and if it exists, execute the playmedia command on that file just as i was able to do with my playvid.py script which contains xbmc.executebuiltin( "PlayMedia(/mnt/usb/video1.mp4)" ). else, i would like it to skip down to the other file. here is what i have, but returns the error of "no module named xbmc". what is the difference of these two and how can i resolve it?
Code:
import xbmc
import os

if os.path.isfile ("/mnt/usb/video2.mp4"):
    xbmc.executebuiltin( "PlayMedia(/mnt/usb/video2.mp4)" )

else:
   xbmc.executebuiltin( "PlayMedia(/mnt/usb/video1.mp4)" )
Reply
#14
Are you trying to execute this script standalone or is it being called from within XBMC? Needs to be the latter.
Reply
#15
@MilhouseVH

Play and wait script works great but is there anyway to have it change instantly once video has completed? currently it is set to 1.0. I tried 0.2 and it locked up my pi. Once video is done playing it shows the rPi home screen and states "working" in the bottom right corner for apx 3-5 seconds.
Reply

Logout Mark Read Team Forum Stats Members Help
Activate Window and Begin Playing1