Key mapping questions

If you need any help with XBMC4XBOX, such as installing or using the software, please post it in here.
Post Reply
Dogfyter
Posts: 28
Joined: Mon Jul 23, 2012 11:51 pm
Has thanked: 6 times

Key mapping questions

Post by Dogfyter »

Hi All,

Does any body have any suggestions for programing the number buttons on the remote to either play a script, playlist, or a mp3?

Also, I have seen scripts that have the option to shuffle. I am looking for code suggestions to have the option to "loop" the same script, playlist, or mp3.

Thanks again, in advance for the help.

Dogfyter
User avatar
Spongy
Posts: 97
Joined: Sun Jul 08, 2012 5:11 am
Has thanked: 16 times
Been thanked: 18 times

Re: Key mapping questions

Post by Spongy »

You should be able to find most of the info you're looking for on these three pages.
Built In Scripting
Built In Functions
Keymap.xml

Here is an example of running a script from a button.

Code: Select all

RunScript(Q:\Scripts\myscript.py)
or

Code: Select all

RunScript(Q:\Scripts\myscript\default.py)
Dogfyter
Posts: 28
Joined: Mon Jul 23, 2012 11:51 pm
Has thanked: 6 times

Re: Key mapping questions

Post by Dogfyter »

Thank you, Spongy.

I had forgotten about these pages. I will definitely put some work on this. Here is one of my favorite scripts. All credit goes to the Author. If anyone knows how to add the "loop" function please, let me know. I would also like to know if there is a way code a script for turning the an added "LCD" on and off. Not "LED" but, "LCD" please.

Here is the mentioned script. Note that it has my "configuration". Alter as you like;



''' vim: ts=8 sw=4 noexpandtab
Author: Rune Hammersland
version: 0.3

Xbox Media Center comes with a script to play an mp3 file at startup
(StartUpMP3). This script will load a playlist if it exists, and if not,
traverse a directory and load all relevant music files. It is intended as a
replacement for StartUpMP3, and enables you to listen to a playlist, or all
music files in a given directory.

Changelog:
2005-05-27 13:10:33 - Rune Hammersland:
* Added possibility for multiple playlists.
* Added possibility for multiple music dirs.

'''

import xbmc
import os

# ---------------------------------------- #
# "Configuration"
# ---------------------------------------- #

# Change this to your playlist(s).
# Written like this: ['path\\to\\plist1', 'to\\plist2', 'plist\\3']
playlist_files= ['E:\\Media\\Music\\playlist.m3u', 'G:\\all.m3u']
# Dirs(s) to traverse if playlist does not exist. NB: No trailing slash.
# Written like this: ['path\\to\\dir1', 'to\\dir2', 'dir\\3']
music_dirs = [':\\Music', 'F:\\Music',':Music\\']
# Shuffle playlist if this var equals 1.
shuffle_files = 1


# ---------------------------------------- #
# Code
# ---------------------------------------- #

# Function for adding files to playlist
def add_files(pl, dirname, names):
for filename in names:
if (os.path.isfile(dirname + "\\" + filename)):
add = 0

# Check extension of file.
if (filename[-4:] == ".mp3"): add = 1
if (filename[-4:] == ".ogg"): add = 1
if (filename[-4:] == ".wav"): add = 1
if (filename[-5:] == ".flac"): add = 1

# If file is to be added, do it.
if (add == 1): pl.add(dirname + "\\" + filename)
elif (os.path.isdir(dirname + "\\" + filename)):
os.path.walk(dirname + "\\" + filename, add_files, pl)

# Get music playlist from XBMC
plist = xbmc.PlayList(0)
plist.clear()

# Load playlist if it exists
for playlist_file in playlist_files:
if (os.path.isfile(playlist_file)):
plist.load(playlist_file)
# Else, find all available music
else:
for music_dir in music_dirs:
os.path.walk(music_dir, add_files, plist)

# Do the shuffle!
if (shuffle_files == 1): plist.shuffle()

xbmc.Player().play(plist)
User avatar
Rocky5
Posts: 974
Joined: Sat Feb 08, 2014 5:27 am
Has thanked: 101 times
Been thanked: 257 times

Re: Key mapping questions

Post by Rocky5 »

Here is a simpler script, that can be run with a custom argument to allow a custom path and 3 custom extensions.

By default it will search E:\F:\G:\Music for mp3,wma or ogg formatted files.

Code: Select all

Removed till I fix it
Last edited by Rocky5 on Mon Sep 05, 2016 5:00 pm, edited 3 times in total.
Download Xbox Softmodding Tool & Extras Disc
XBMC4Kids Mod


Xbox Gamertag = Connxtion
PSN ID = JCRocky5
Dogfyter
Posts: 28
Joined: Mon Jul 23, 2012 11:51 pm
Has thanked: 6 times

Re: Key mapping questions

Post by Dogfyter »

Spongy,

Thanks again, I now have my first working script button.


Rocky5,

I am guessing this script has to used with xbmc4kids? I am trying to use it as an app. I have removed/renamed the Profiles.py as suggested but, I still can't get past the opening page with profiles and settings. Any suggestions? I can't figure out xbmc4kids. LOL Thanks in advance for the help.

Dogfyter
User avatar
Rocky5
Posts: 974
Joined: Sat Feb 08, 2014 5:27 am
Has thanked: 101 times
Been thanked: 257 times

Re: Key mapping questions

Post by Rocky5 »

Dogfyter wrote:Spongy,

Thanks again, I now have my first working script button.


Rocky5,

I am guessing this script has to used with xbmc4kids? I am trying to use it as an app. I have removed/renamed the Profiles.py as suggested but, I still can't get past the opening page with profiles and settings. Any suggestions? I can't figure out xbmc4kids. LOL Thanks in advance for the help.

Dogfyter
It's a script, it can be used in any skin.

To bypass the profile screen you only need to change 1 thing. (No need to remove stuff anymore if you are using the latest version from my GitHub)

Edit the profiles.xml and change on the third line true to false. You will boot into the profiles manager skin now you can change the skin in the settings menu.

As for the script

Example with arguments, you could add this to startup.xml or have it as a button. Exact same way Spongy stated.

Default mode, this will get music from E,F or G:\Music\ in MP3, WMA or OGG format.

Code: Select all

RunScript ( Special://xbmc/scripts/what ever you called it.py )
Custom mode, with argument. This will load music from G:\My Music\ in MP3, WMA or OGG format.

Code: Select all

RunScript ( Special://xbmc/scripts/what ever you called it.py,G:\My Music\ )
Custom mode alt, with argument. This will load music from G:\My Music\ in MP3, WMA or WAV format.

Code: Select all

RunScript ( Special://xbmc/scripts/what ever you called it.py,G:\My Music\,mp3,wma,wav )

I fixed the example paths in the script, habit having it that path, also for some reason the script part was missing :? so fixed that also.
Download Xbox Softmodding Tool & Extras Disc
XBMC4Kids Mod


Xbox Gamertag = Connxtion
PSN ID = JCRocky5
Dogfyter
Posts: 28
Joined: Mon Jul 23, 2012 11:51 pm
Has thanked: 6 times

Re: Key mapping questions

Post by Dogfyter »

Rocky5,

Thanks for the response. I downloaded xbmc4kids from the link in your signature. I do not know if that is the latest. It says 06/2016. The script wants to work but, it is only playing one second of a song and, then jumping to the next song. ongoing... I'm not a programmer but, first guess is the sleep function "time.sleep(1)". What should I change?

Thanks,
dogfyter
User avatar
Rocky5
Posts: 974
Joined: Sat Feb 08, 2014 5:27 am
Has thanked: 101 times
Been thanked: 257 times

Re: Key mapping questions

Post by Rocky5 »

Dogfyter wrote:Rocky5,

Thanks for the response. I downloaded xbmc4kids from the link in your signature. I do not know if that is the latest. It says 06/2016. The script wants to work but, it is only playing one second of a song and, then jumping to the next song. ongoing... I'm not a programmer but, first guess is the sleep function "time.sleep(1)". What should I change?

Thanks,
dogfyter
Yeah I know whats up, fixing it just now.

Fixed.

Code: Select all

'''
	Script by Rocky5
	Used to create a playlist from a specific directory and play it back shuffled and repeated.

		Usage:
			This script uses arguments, so to use it you add characters/paths to the end of the RunScript command.

			Below will build a playlist using the path and extension, in this case using 3 custom extensions.
				<onclick>RunScript( Special://xbmc/scripts/XBMC4Kids/Utilities/Random Screensaver Images.py,G:\Music\My Music\,aac,wav,flac)</onclick>
			Same as above but uses default values for getting files.
				<onclick>RunScript( Special://xbmc/scripts/XBMC4Kids/Utilities/Random Screensaver Images.py)</onclick>
'''
				
				
import glob, os, time, xbmc

try:
	Music_Path = sys.argv[1]
except:
	Music_Path = [ "E:\\Music\\","F:\\Music\\","G:\\Music\\" ]
try:
	Music_Extension = sys.argv[2][3][4]
except:
	Music_Extension = [ "mp3","wma","ogg" ]
	
Playlist = xbmc.translatePath( "special://Profile/playlists/music/random.m3u" )

for Music_Dir in Music_Path:
	if os.path.isdir( Music_Dir ):
		f = open( Playlist,"w" )
		for Music_Extension in Music_Extension:
			Music_Files = glob.glob( os.path.join( Music_Dir, "*." + Music_Extension ) )
			for Files in Music_Files:
				if os.path.isfile( Files ):
					f.write( "#EXTM3U\n" )
					FileExt = Files.replace( Music_Dir,"" )
					line	= '#EXTINF:0,' + FileExt[:-4] + '\n' + Files + '\n'
					f.write(line)
		f.close
		xbmc.executebuiltin( "PlayMedia(" + Playlist + ")" )
		xbmc.PlayList( 0 ).shuffle()
		xbmc.executebuiltin( "playercontrol(RepeatAll)" )
	else:
		print "Error: " + Music_Dir + " path not found."
Download Xbox Softmodding Tool & Extras Disc
XBMC4Kids Mod


Xbox Gamertag = Connxtion
PSN ID = JCRocky5
Dogfyter
Posts: 28
Joined: Mon Jul 23, 2012 11:51 pm
Has thanked: 6 times

Re: Key mapping questions

Post by Dogfyter »

Rocky5,

Updates. The script works now but seems to only work half the time. When it does work it is much faster than the script I provided. I have the script in the usual script folder. Any suggestions for consistency.

XBMC4Kids the 3rd line of the profile.xml is set to "false" as default. I was able to figure out how to change the skin to confluence lite one time and have not been able to find that setting again. The settings options are the same for the master profile, dvd2xbox, and my new profile. They all only have the display and the network setting options.

Thanks in advance for help.
User avatar
Rocky5
Posts: 974
Joined: Sat Feb 08, 2014 5:27 am
Has thanked: 101 times
Been thanked: 257 times

Re: Key mapping questions

Post by Rocky5 »

Dogfyter wrote:Rocky5,

Updates. The script works now but seems to only work half the time. When it does work it is much faster than the script I provided. I have the script in the usual script folder. Any suggestions for consistency.

XBMC4Kids the 3rd line of the profile.xml is set to "false" as default. I was able to figure out how to change the skin to confluence lite one time and have not been able to find that setting again. The settings options are the same for the master profile, dvd2xbox, and my new profile. They all only have the display and the network setting options.

Thanks in advance for help.
I need a log to see why, it work fine for me every time. (Tested it with over 200 MP3 tracks)

If you're not going to use my skin, there isn't much point using my XBMC4Kids. Just install XBMC 3.5.3.

But to change skins it's in setting > appearance

Also it's not set to false by default :? as the login screen is enabled by default.
(You can't just transfer the skins over, as features won't work, you need to use the build bat that's included with the hole package)

Download Xbox Softmodding Tool & Extras Disc
XBMC4Kids Mod


Xbox Gamertag = Connxtion
PSN ID = JCRocky5
Dogfyter
Posts: 28
Joined: Mon Jul 23, 2012 11:51 pm
Has thanked: 6 times

Re: Key mapping questions

Post by Dogfyter »

Hi Rocky5,

Thanks. You were right about the skin setting being "true". The Xbmc4Kids folder must not have extracted completely from the iso. With the skin setting set either at "true" or "false" I am unable to find the any settings other than video display and network settings. I will have to try extracting the folder again another time.

On a lighter note. I am STOKED about your playlist script. I looked at the log like you mentioned and noticed errors for the looking script looking for music files that were not there (E & G:\Music\). Once took those out of the script it ran like a champ. I put your script in the autoexec.py and now all my F:\Music\ starts random at boot. That would crash my xbox half the time with the old script. I had given up on all my music starting random at boot. So thank you again for that!

Here is another question about a script I would like your advice on.

import xbmc

# By alx5962
# version 1.0

file = 'q:\\scripts\\StartUpMP3\\startup.mp3'

xbmc.Player().play(file)

It is a very simple straight forward script. Again, I am not a programmer but, I tried to add a line from your script to get it the mp3 to loop/ repeat.

xbmc.executebuiltin( "playercontrol(RepeatAll)"

I added this line to end of this script with no luck with looping. Any suggestions? If not, no big deal. I appreciate all of the previous help.

Thanks again,
Dogfyter
User avatar
Rocky5
Posts: 974
Joined: Sat Feb 08, 2014 5:27 am
Has thanked: 101 times
Been thanked: 257 times

Re: Key mapping questions

Post by Rocky5 »

Dogfyter wrote:Hi Rocky5,

Thanks. You were right about the skin setting being "true". The Xbmc4Kids folder must not have extracted completely from the iso. With the skin setting set either at "true" or "false" I am unable to find the any settings other than video display and network settings. I will have to try extracting the folder again another time.

On a lighter note. I am STOKED about your playlist script. I looked at the log like you mentioned and noticed errors for the looking script looking for music files that were not there (E & G:\Music\). Once took those out of the script it ran like a champ. I put your script in the autoexec.py and now all my F:\Music\ starts random at boot. That would crash my xbox half the time with the old script. I had given up on all my music starting random at boot. So thank you again for that!

Here is another question about a script I would like your advice on.

import xbmc

# By alx5962
# version 1.0

file = 'q:\\scripts\\StartUpMP3\\startup.mp3'

xbmc.Player().play(file)

It is a very simple straight forward script. Again, I am not a programmer but, I tried to add a line from your script to get it the mp3 to loop/ repeat.

xbmc.executebuiltin( "playercontrol(RepeatAll)"

I added this line to end of this script with no luck with looping. Any suggestions? If not, no big deal. I appreciate all of the previous help.

Thanks again,
Dogfyter
What you done shouldn't have made any difference as it looks for the files and only if it finds them does it add them to the random.m3u, but if what you done works then good :D

Code: Select all

import xbmc
file = 'Q:\\scripts\\StartUpMP3\\startup.mp3'
xbmc.executebuiltin('xbmc.PlayerControl(RepeatAll)')
xbmc.executebuiltin('xbmc.PlayMedia(file)')
Download Xbox Softmodding Tool & Extras Disc
XBMC4Kids Mod


Xbox Gamertag = Connxtion
PSN ID = JCRocky5
Post Reply