gpt4 book ai didi

python-mplayer 无法打开 mp3 文件

转载 作者:行者123 更新时间:2023-12-01 04:59:11 25 4
gpt4 key购买 nike

嗨,我正在尝试构建一个小型音频播放器,将 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

最佳答案

我不熟悉 mplayer API,但也许这只是一个小疏忽:

p.loadfile('audiofile')

应该是

p.loadfile(audiofile)

因为文件的路径位于变量audiofile中,而不是字符串'audiofile'

关于python-mplayer 无法打开 mp3 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26675470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com