.exe文件关闭时,我点击按钮在用户界面,应该播放音乐文件
.exe file closes when i click the button in the userinterface which is supposed to play music file
我是QT的新手,我想通过QT播放音乐文件,其界面包含一个播放按钮,这样当我点击播放按钮时,歌曲应该播放。现在当我运行程序时,我得到我的界面,但不幸的是,当我点击播放按钮时,它说。exe文件停止工作,它被关闭,在QT创建器窗口中显示255的退出错误代码..这里是主窗口。
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "audiere.h"
using namespace audiere;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//connect(ui->Number1,SIGNAL(textChanged(QString)),this,SLOT(numberChanged()));
connect(ui->play,SIGNAL(clicked()),this,SLOT(PLAY()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::PLAY() {
AudioDevicePtr device(OpenDevice());
OutputStreamPtr sound(OpenSound(device,"lk.mp3",true));
sound->play();
sound->setRepeat(true);
sound->setVolume(2.0);
}
我有三个建议:
首先,添加错误检查。
第二,考虑使用Ogg Vorbis,如果你有mp3的问题。
第三,将指针移动为MainWindow的成员变量,而不是局部作用域变量。Audiere可能在过早地清理它们。
在Audiere中使用错误检查
这是来自Audiere下载的doc文件夹中的"tutorial.txt":
你需要打开AudioDevice才能播放声音…
AudioDevicePtr device(OpenDevice());
if (!device) {
// failure
}
现在我们有了一个设备,我们就可以打开并播放声音了。
/*
* If OpenSound is called with the last parameter = false, then
* Audiere tries to load the sound into memory. If it can't do
* that, it will just stream it.
*/
OutputStreamPtr sound(OpenSound(device, "effect.wav", false));
if (!sound) {
// failure
}
/*
* Since this file is background music, we don't need to load the
* whole thing into memory.
*/
OutputStreamPtr stream(OpenSound(device, "music.ogg", true));
if (!stream) {
// failure
}
太好了,我们有一些开放的流!我们该怎么处理它们?
最新MP3支持的常见问题解答
在faq页面中也有一个警告:
从1.9.2版本开始,Audiere支持MP3图书馆。然而,很少有兼容lgpl的MP3代码它适用于各种mp3和硬件。我强烈推荐使用Ogg Vorbis来满足你所有的音乐需求。它使用和听起来更好。
当Audiere清理时
在教程的底部,它提到了清理发生的时间:
当你完成使用Audiere,只是让RefPtr对象出去作用域,它们会自动清理自己。如果你真的必须在对象的指针超出作用域之前删除对象,只需将指针设置为0。
希望对你有帮助。
相关文章:
- Qt5 用户界面编译器:-i 选项不可用
- QMenuBar 不使用原生样式? c++ , QTDesigner.用户界面
- 如何将C 中的后端写入与TCL/TCK用户界面连接
- 是否可以通过图形用户界面 (GUI) 与 Linux 命令行界面 (CLI) 进行交互
- 拥有用于QT应用程序的Web用户界面的最佳方法
- 面向海思处理器的用户界面SDK
- 如何在C++中使用我自己的库创建用户界面
- 使用 C++ 进行用户界面设计
- QT 图形用户界面进度条
- 用户界面在 qt 应用程序中未更新
- 带有 c++ 的图形用户界面.当我使用按钮时滞后
- Leap Motion C++的用户界面
- C++图形用户界面和控制台应用程序
- 在C++中实现一个基于文本命令的用户界面
- 向图像查看器插件添加用户界面
- 在内存中渲染用户界面
- Dektop和metro Windows 8的通用用户界面
- Linux上的用户界面
- .exe文件关闭时,我点击按钮在用户界面,应该播放音乐文件
- 用户界面-如何在C++中将gui与逻辑分离(通信2个可执行文件所需的模式和库)