Problem with phonon in another class
Hello. I want to do a litte music player based on phonon libs.
I want to make another class with operations like play, stop etc.
Code:
#include "plik.h"
#include <QString>
#include <QDebug>
#include <phonon/Global>
#include <phonon/MediaObject>
#include <phonon/AudioOutput>
#include <phonon/MediaSource>
#include <phonon/Path>
Phonon::MediaObject *mediaObject;
Phonon::AudioOutput *audioOutput;
Plik::Plik()
{
this->next = NULL;
this->prev = NULL;
}
{
this->path = path;
return;
}
{
return this->path;
}
void Plik::playFile()
{
mediaObject = new Phonon::MediaObject(this);
audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory,this);
mediaObject->setCurrentSource(Phonon::MediaSource("/home/matulik/test.mp3"));
audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory,this);
Phonon::Path path = Phonon::createPath(mediaObject,audioOutput);
mediaObject->setTickInterval(1000);
audioOutput->setVolume(100);
audioOutput->setMuted(FALSE);
mediaObject->play();
}
And in mainwindow:
Code:
Plik p1;
p1.playFile();
And this doesnt work.
I dont know where is the problem, becouse the same source code coping to mainwindow works..
Code:
#include "odplayer.h"
#include "ui_odplayer.h"
#include "plik.h"
#include <QString>
#include <QDebug>
#include <phonon/Global>
#include <phonon/MediaObject>
#include <phonon/AudioOutput>
#include <phonon/MediaSource>
#include <phonon/Path>
Phonon::MediaObject *mediaObject;
Phonon::AudioOutput *audioOutput;
odplayer
::odplayer(QWidget *parent
) : ui(new Ui::odplayer)
{
ui->setupUi(this);
mediaObject = new Phonon::MediaObject(this);
audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory,this);
mediaObject->setCurrentSource(Phonon::MediaSource("/home/matulik/test.mp3"));
audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory,this);
Phonon::Path path = Phonon::createPath(mediaObject,audioOutput);
mediaObject->setTickInterval(1000);
audioOutput->setVolume(100);
audioOutput->setMuted(FALSE);
mediaObject->play();
}
odplayer::~odplayer()
{
delete ui;
}
Someone can help?
Re: Problem with phonon in another class
In this code, what is wrong?
Code:
void func()
{
Plik p1;
p1.playFile();
}
fyi:
posting code like this
Code:
Plik p1;
p1.playFile();
is not helpful at all because there is no context, e.g. class + method name
Re: Problem with phonon in another class
Its like this:
Code:
#include "odplayer.h"
#include "ui_odplayer.h"
#include "plik.h"
#include <QString>
#include <QDebug>
#include <phonon/Global>
#include <phonon/MediaObject>
#include <phonon/AudioOutput>
#include <phonon/MediaSource>
#include <phonon/Path>
Phonon::MediaObject *mediaObject;
Phonon::AudioOutput *audioOutput;
odplayer
::odplayer(QWidget *parent
) : ui(new Ui::odplayer)
{
ui->setupUi(this);
Plik p1;
p1.playFile();
}
odplayer::~odplayer()
{
delete ui;
}
Re: Problem with phonon in another class
yeah, now tell me what is wrong with this
Code:
odplayer
::odplayer(QWidget *parent
) : ui(new Ui::odplayer)
{
ui->setupUi(this);
Plik p1;
p1.playFile();
}
Hint: It's a c++ 'thing'.
Re: Problem with phonon in another class
Ok, I know where is problem:
Code:
File* f1 = new File;
f1->setPath("/home/matulik/test.mp3");
qDebug()<<f1->returnPath();
f1->playFile();
Thanks very much for hint :)
Re: Problem with phonon in another class
what's a `File`? I haven't seen that in your previous code. And what did I just say about posting code with no context?
By the way, you now have a memory leak.