xbmc.Player().play() does not play my file
#1
Question 
Hi everyone again,

i'm trying to play a file via the funtion xbmc.player().play(file) ! the file is stored on a smb network share (smb://test:[email protected]/Music/03 - Song.ogg). when i call the function with the given address the player does not do anything!? is the address incorrect or the function deprecated?

Is there perhaps another function which can stack up items in the playlist?

Sorry for my bad english und best regards

koprom
Reply
#2
Exclamation 
I've found out that the problem is the address of the file. If i put a file test.ogg to drive E on the xbox i can play this file without any problems. Is this function limited to files from local drives? or is smb mapped to specific drive letter?

Greetings

koprom
Reply
#3
Question 
I can't get the xbox to play the file. Tried every combinatino of slashes or backslashes in the location of the file. It doesn't work. I thought it would be enough to concatenate the 'strPath' Value from the database-table path and the 'strFileName' Value from the table song. But this doesn't work? Are Python scripts limited to local files?

Greetings

koprom
Reply
#4
try using this instead
XBMC.PlayMedia(medialocation) for example

XBMC.PlayMedia(F/stuff/test.avi)
Reply
#5
Now python gives the error message: module 'xbmc' has no attribute 'PlayMedia'

Greetings koprom
Reply
#6
Is this in Python?

You can give this a try:

file = "F:\music\test.mp3"

print xbmc.executebuiltin('xbmc.playmedia(' + file + ')')

print xbmc.executehttpapi("AddToPlaylist("+file+");0")

command=PlayFile&parameter=F:\music\test.mp3
Reply
#7
When trying this:

file = "smb://test:[email protected]/Music/01 - Song.ogg"

print xbmc.executebuiltin('xbmc.playmedia(' + file + ')')

print xbmc.executehttpapi("AddToPlaylist("+file+");0")

the output was:

<li> Error
None
<li> Error

Greetings

koprom
Reply
#8
Code:
import xbmc, xbmcgui

def get_browse_dialog( default="", heading="", type=1, shares="files", mask="", use_thumbs=False, treat_as_folder=False ):
    """ shows a browse dialog and returns a value
        - 0 : ShowAndGetDirectory
        - 1 : ShowAndGetFile
        - 2 : ShowAndGetImage
        - 3 : ShowAndGetWriteableDirectory
    """
    dialog = xbmcgui.Dialog()
    value = dialog.browse( type, heading, shares, mask, use_thumbs, treat_as_folder, default )
    return value

file = get_browse_dialog( heading="Song to play", mask=".mp3|.ogg" )
print file
xbmc.Player().play( file )

The above works fine for me, though I don't use passwords.

Use that and then see if the file you want plays, if so view the debug output and see what the line should look like.

Also make sure you have a share to that folder or atleast a smb:// share in filemanager.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#9
Okay i tried your script and it works perfectly even with passworded shares. I combined it with my script to find differences in the smb address.

Here is my script with some imports left out:

Code:
band = 'Coldplay'

cur.execute("SELECT idArtist FROM artist WHERE strArtist = '" + band + "'")
row = cur.fetchone()
if(not row == None):
    band_id = str(row[0])

cur.execute("SELECT idPath, strFileName FROM song WHERE idArtist = '" + band_id + "' AND strTitle = '" + songname + "'")
row = cur.fetchone()
if(not row == None):
    idPath = str(row[0])
    filename = row[1]

if(not idPath == ''):
    cur.execute("SELECT strPath FROM path WHERE idPath = '" + idPath + "'")
    row = cur.fetchone()
    path = str(row[0])
    complete = path + filename

print complete

#==================

def get_browse_dialog( default="", heading="", type=1, shares="files", mask="", use_thumbs=False, treat_as_folder=False ):
    """ shows a browse dialog and returns a value
        - 0 : ShowAndGetDirectory
        - 1 : ShowAndGetFile
        - 2 : ShowAndGetImage
        - 3 : ShowAndGetWriteableDirectory
    """
    dialog = xbmcgui.Dialog()
    value = dialog.browse( type, heading, shares, mask, use_thumbs, treat_as_folder, default )
    return value

file = get_browse_dialog( heading="Song to play", mask=".mp3|.ogg" )
print file

#=================

test = ("smb://test:[email protected]/Musik/Coldplay/2000 - Parachutes/05 - Yellow.ogg")
print test

xbmc.Player().play( complete ) # Does not work
xbmc.Player().play( file ) # Works
xbmc.Player().play( test ) # Works

And this is the Output as seen on my TV or in the test environment on the pc:

Code:
smb://test:[email protected]/Musik/Coldplay/2000 - Parachutes/05 - Yellow.ogg
smb://test:[email protected]/Musik/Coldplay/2000 - Parachutes/05 - Yellow.ogg
smb://test:[email protected]/Musik/Coldplay/2000 - Parachutes/05 - Yellow.ogg

There is no difference in the output of the strings, so perhaps they have a different type (i'm not a python expert)? Or do i have to escape the string?

Thanks for your help nuka1195

Greetings

koprom
Reply
#10
Big Grin 
Okay i've found the solution. With the python function 'type' i found out that sqlite does not return objects of the type 'str' (as play needs them) but unicode objects (which play regrets)!

The solution is every unicode object has a function encode('charset') where charset could be 'utf-8' which i use at the moment. This function return a 'str' object with the (hopefully) the same contents as the unicode object.

Greetings

koprom
Reply

Logout Mark Read Team Forum Stats Members Help
xbmc.Player().play() does not play my file0