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

查看:27
本文介绍了在 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 exited with value 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 相关联,这在其他操作系统上是否可行?

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:

以上所有内容都使用 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天全站免登陆