嗨,Iam尝试构建一个小型音频播放器,将mplayer集成到python中
我认为python-mplayer可以完成这项工作,但我无法让它工作。有什么想法吗?
似乎p.loadfile不像ps ax显示那样工作 / usr / bin / mplayer -slave -idle -really-quiet -msglevel global = 4 -input nodefault-bindings -noconfig all
import pygame
import os
import subprocess
import sys
import time
import subprocess
from mplayer import *
audiofile = "/home/user/1.mp3"
gfx_rev_normal = pygame.image.load('rev_normal.png')
pygame.init()
screen = pygame.display.set_mode((800, 480))
#background = pygame.Surface(screen.get_size())
#background = background.convert()
#background.fill = ((255, 255, 255))
font = pygame.font.SysFont("monospace", 36)
source_text = font.render("Audio Player", 1, (255, 255, 255))
text_width = source_text.get_width()
source_text_x = screen.get_width() / 2
source_text_x = source_text_x - (text_width/2)
source_text_y = 10
screen.blit(source_text,(source_text_x, source_text_y))
Player.exec_path="/usr/bin/mplayer"
p = Player()
p.loadfile('audiofile')
#p.pause()
p.volume=100
running = True
while running:
time.sleep(0.1)
print p.stream_pos
screen.blit(gfx_rev_normal,(30,120))
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
running = False
答案 0 :(得分:2)
我不熟悉mplayer API,但也许这只是一个小小的疏忽:
p.loadfile('audiofile')
应该是
p.loadfile(audiofile)
因为文件的路径位于变量audiofile中,而不是字符串'audiofile'
。