0

我将歌曲名称传递给函数,但无法为 omxplayer 构建路径

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")

如何将“pathsong”放入 omxplayer 命令行?

4

1 回答 1

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)
于 2016-09-20T00:01:10.643 回答