在Python中播放和控制mp3文件? [英] Playing and controlling mp3 files in Python?

查看:328
本文介绍了在Python中播放和控制mp3文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我是一名Python初学者,具有典型的C ++/Java背景知识,面向对象.

First things first, I am a Python beginner, with a typical C++/Java background for object oriented stuff.

我被说服为目前的这项工作尝试使用Python,到目前为止,我还是喜欢它.我遇到的一个问题是找到一个好的mp3模块.

I was convinced to try Python for this current endeavor I am working on, and so far I like it. One issue I am having though is finding a good mp3 module.

我尝试了TkSnack,它安装并运行正常,没有任何错误(只要我的音频设备不忙),但它实际上无法发出声音,它什么也没做……我上网寻求帮助,并且对文档数量感到失望.

I have tried TkSnack, which installed and ran fine with no errors(as long as my audio device wasn't busy) but it could never actually produce a sound, it just did nothing... I went online for help, and was disappointed with the amount of documentation.

所以我决定切换.我尝试了PyMad,因为它也在Ubuntu的标准存储库中.关于此的文档甚至更少,但我可以使它播放声音.唯一的问题是,它需要循环才能不断地写入/播放音频缓冲区.这使得处理播放控制特别麻烦(我认为),因为我将不得不在单独的线程或进程中运行该播放控制,并以某种方式控制寻求位置的暂停等.对于我为什么使用Python,这有点太低了.我喜欢TkSnack的简单性,因为它的命令很简单,例如"mysound.play()"或"mysound.pause()",而不是控制循环.

So I decided to switch. I tried PyMad because it is in the standard repositories for Ubuntu as well. There was even less documentation on this, but I could make it play a sound. The only problem is that it requires a loop to constantly write/play the audio buffer. This makes it particularly hairy to handle playback control(in my opinion) cause I would have to run this in a separate thread or process, and somehow control the seek position for pause and such. This is a little too low level for why I am using Python. I liked the simplicity of TkSnack for its easy commands like "mysound.play()" or "mysound.pause()" rather than controlling a loop.

我还查看了pyMedia,它看起来是最新的文档,但是我无法将其安装在我的计算机上.运行"python setup.py build"命令时,出现"gcc退出,值为1"错误或类似的错误.

I also looked at pyMedia, which looks like it is the most up to date with documentation, but I can't get it to install on my machine. I get a "gcc exited with value 1" error or something like that when running the "python setup.py build" command.

因此,我正在寻找有关这些模块之一或完全不同的模块的任何建议或帮助,即高水平且易于使用的mp3(最好还有其他格式),我正在尝试具有基本的播放控制(暂停,停止,跳过,查找),而且我最终也可能会流式传输文件(如果我到达那里).

So I am looking for any suggestions or help on one of these modules, or a completely different one, that is high level and easy to use for mp3s(and preferably other formats too) I am trying to have basic playback control(pause, stop, skip, seek) and I may also be streaming files too eventually(if I ever get there).

编辑:我喜欢Gstreamer的python绑定,但这是跨平台的解决方案吗?我忘了提到这一点.但是我始终只是将GStreamer与Linux关联,这可以在其他OS上使用吗?

EDIT: I like the python bindings for Gstreamer, but is this a cross-platform solution?? I forgot to mention that as a requirement. But I always just associated GStreamer with Linux, would this work on other OSs?

编辑:维基百科说.

推荐答案

抱歉,PyMad或pyMedia无法为您提供帮助,但是我还有其他建议.

Sorry I can't help you with PyMad or pyMedia, but I have other suggestions.

使用Python编写的现有音乐播放器:

Existing music players written in Python:

  • Exaile
  • FUPlayer
  • Listen

上述所有方法均将 Python绑定用于 GStreamer 多媒体框架.用于绑定的文档很少,但是请在此处此处.

All of the above use the Python bindings for the GStreamer multimedia framework. Docs for the bindings are scarce, but check here, here, here, and examples from the source distribution here.

这篇关于在Python中播放和控制mp3文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆