This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Music Player with Qt

Tags: None
(comma "," separated)
vijay
Registered Member
Posts
4
Karma
0
OS

Music Player with Qt

Wed Jul 07, 2010 4:18 am
Hi

I have created a simple music player using Qt creator IDE.

As I add mp3 files to my playlist and then play them using this music player, it takes a lot of time for loading (practically infinite) .

Please help me with this problem

Secondly, as i tried to add an audio file of .wav format , i got the following error


(<unknown>:1998): GStreamer-CRITICAL **: gst_element_make_from_uri: assertion `gst_uri_is_valid (uri)' failed

So, is this true that Qt does not support audio files in .wav format

Please help me with the above problems

Thanks in advance
User avatar
giucam
KDE Developer
Posts
62
Karma
1
OS

Re: Music Player with Qt

Sun Jul 11, 2010 8:10 pm
As regards the first problem, it's difficult to say without knowing a single line of code.

Anyway I suppose you're using Phonon, right? Phonon, so Qt, doesn't support a single audio format, it relies on a backend which know how to handle those files, like GStreamer, Xine, VLC, Mplayer,..., so if you can't read an audio format the "fault" is of the backend you're using.
vijay
Registered Member
Posts
4
Karma
0
OS

Re: Music Player with Qt

Mon Jul 12, 2010 12:59 pm
Thanks for your reply.

I am using Phonon which uses Gstreamer for its backend.

I have installed all gstreamer plugins on my system.

Yet as i add mp3 files phonon::mediaObject->state() continuously returns loading state.Hence it is not able to move out of loading state.

As I add .wav or .ogg files i get the following error:

(<unknown>:1998: GStreamer-CRITICAL **: gst_element_make_from_uri: assertion `gst_uri_is_valid (uri)' failed .


I tried running the Phonon music player available at link http://doc.qt.nokia.com/4.7-snapshot...sicplayer.html also , but suffered from same problems with this music player as well.

I downloaded KMPlayer which is a media player built using Qt and Phonon.This music player is also unable to play any audio file and i get similar results with it.
i.e. no errors with .mp3 files , yet player shows Player Phonon Buffering State as i try to play any audio file and hence does not play any sound.
And it shows similar error as abovementioned with .wav and .ogg files

I am using Ubuntu 9.10. and have installed Qt 4.5

Please help.I need it desperately.
vijay
Registered Member
Posts
4
Karma
0
OS

Re: Music Player with Qt

Mon Jul 12, 2010 1:24 pm
I am now pasting source code of two important files of my project as well
I have used Qt Creator IDE.

FILE:mainwindow.h

#include <QList>
#include<QtGui/QMainWindow>
#include <QFileDialog>
#include<QListView>
#include <QDesktopServices>
#include <phonon>
#include <QDebug>
#include<fstream>
#include<iostream>
#include<algorithm>
using namespace std;


#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>

namespace Ui
{
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void playPause();
void addFiles();
void nextFile();
void aboutToFinish();
void finished();


private:
Ui::MainWindow *ui;
QList<Phonon::MediaSource> sources;
Phonon::MediaObject *mediaObject;
Phonon::AudioOutput *audioOutput;
Phonon::MediaObject *metaInformationResolver;

};

#endif // MAINWINDOW_H

FILE:mainwindow.cpp

#include "mainwindow.h"
#include<QtGui>
#include<stdlib.h>
#include<string.h>
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
mediaObject = new Phonon::MediaObject(this);
metaInformationResolver = new Phonon::MediaObject(this);
Phonon::createPath(mediaObject, audioOutput);

ui->setupUi(this);
}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::playPause()
{
switch (mediaObject->state()){
case Phonon::ErrorState:
qDebug()<<"\nIn Error State";
if (mediaObject->errorType() == Phonon::FatalError) {
QMessageBox::warning(this, tr("Fatal Error"),
mediaObject->errorString());
} else {
QMessageBox::warning(this, tr("Error"),
mediaObject->errorString());
}
break;

case Phonon::PlayingState:
mediaObject->pause();
qDebug()<<"\nEarlier I was Playing ";
ui->pushButtonPlay->setChecked(false);
break;
case Phonon::PausedState:
qDebug()<<"\nI was in Paused State";
mediaObject->play();
break;
case Phonon::StoppedState:
qDebug()<<"\nI was in Stopped State";
mediaObject->play();
break;
case Phonon::LoadingState:
qDebug()<<"\nI am in Loading State";
ui->pushButtonPlay->setChecked(false);
break;
}
}

void MainWindow::addFiles()
{
QStringList files = QFileDialog::getOpenFileNames(this, tr("Select Music Files"),
QDesktopServices::storageLocation(QDesktopServices::MusicLocation));

ui->pushButtonPlay->setChecked(false);
if (files.isEmpty())
{
qDebug()<<"No File To Add";
return;
}
int index = sources.size();
qDebug()<<sources.size();
qDebug()<<"\nIndex : "<<index;
foreach (QString string, files) {
Phonon::MediaSource source(string);
sources.append(source);
qDebug()<<"\tappending ";
}
qDebug()<<"\nAll files Appended";
if (!sources.isEmpty()){
qDebug()<<"\nSources not empty"<<index<<" "<<sources.size()<<" ";
metaInformationResolver->setCurrentSource(sources.at(index));
mediaObject->setCurrentSource(metaInformationResolver->currentSource());
qDebug()<<mediaObject->state();

}
//int j=0;
//while(mediaObject->state()==Phonon::LoadingState);
qDebug()<<"Loaded ";
}

void MainWindow::nextFile()
{

int index = sources.indexOf(mediaObject->currentSource()) + 1;

if (sources.size() > index) {
mediaObject->stop();
mediaObject->setCurrentSource(sources.at(index));
mediaObject->play();
}
}

void MainWindow::aboutToFinish()
{

int index = sources.indexOf(mediaObject->currentSource()) + 1;

if (sources.size() > index) {
mediaObject->enqueue(sources.at(index));
} else {
ui->pushButtonPlay->setChecked(false);
}

}

void MainWindow::finished()
{
ui->pushButtonPlay->setChecked(false);
}




Please help.


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]