2016-09-19 64 views
0

我传递一个歌曲名称的功能,无法管理,构建路径omxplayer传递歌曲的名字在Python

def PlayMusic(song): 
    #check if the process exists 
    is_pid = subprocess.call("pidof omxplayer.bin > /dev/null", shell=True) 
    if is_pid == 0: 
    return musicplaying("Song already Playing") 
    else: 
    pathsong ='/home/pi/'+song 
    os.system('omxplayer --no-keys -o local pathsong &') 
    return musicplaying (song +" playing") 

到omxplayer我怎么把“pathsong”到omxplayer命令行?

回答

0

这确实我在想什么

@webiopi.macro 
def PlayMusic(song): 
    #check if the process exists 
    is_pid = subprocess.call("pidof omxplayer.bin > /dev/null", shell=True) 
    if is_pid == 0: 
    # Don't play song 
    msg = 'Song already playing - please wait' 
    else: 
    path = '/home/pi/music' 
    for infile in glob.glob(os.path.join(path, song)): 
     a = subprocess.call([ "omxplayer", "--no-keys", "-o", "local", infile, "&"]) 
    msg = 'Now playing ' + song 
    return (msg)