PDA

View Full Version : play from buffered file not working (phonon)



yandi
5th July 2012, 09:39
Hi..All,

need some advice I try make test code to play video file (mp4,avi) using phonon, when set media source from a file it's work OK
but when I try using QBuffer as media source it's won't show the video what am I missing in here??



QFile video("/home/yandi/doc/videotester/BMW.mp4");
video.open(QIODevice::ReadOnly ) ;
QByteArray byteArray;
if(video.exists())
{
byteArray = video.readAll();
qDebug() << byteArray.size();
} else
qDebug() << "File Does not exist";
QBuffer buffer(&byteArray);
qDebug() << buffer.size();

media = new Phonon::MediaObject();
//media->setCurrentSource(Phonon::MediaSource("/home/yandi/doc/videotester/BMW.mp4"));
media->setCurrentSource(Phonon::MediaSource(&buffer));

Phonon::VideoPlayer *videoPlayer = new Phonon::VideoPlayer(Phonon::VideoCategory,this);
videoPlayer->setFixedSize(QSize(400,300));
videoPlayer->move(0,11);
videoPlayer->show();
videoPlayer->play(media->currentSource());



Regards
Yandi

wysota
5th July 2012, 09:43
Doesn't your buffer go out of scope?

yandi
5th July 2012, 10:37
Hi.. Wysota

I'm not quit understand of your question, please enlighten me
but if I check the size of buffer and bytearray is same. should I use "new" operator?

rgds
yandi

wysota
5th July 2012, 10:49
In C++ a local variable declared in some scope is destroyed when the flow leaves the scope:


// ...
{
int a = 7;
}
qDebug() << a; // error -- a undeclared

You need to make the buffer persist throughout the lifetime of the media object.

yandi
5th July 2012, 11:19
oo..i see
first in debug I don't see any error (just didn't show the video widget), second then I try declare the buffer in header class result is same.
I use this example code, in this one video is show but maybe it's different way. I try to integrate this method in my code .


QFile video("/home/yandi/doc/videotester/BMW.mp4");
video.open(QIODevice::ReadOnly ) ;
QByteArray byteArray;
if(video.exists())
{
byteArray = video.readAll();
qDebug() << byteArray.size();
} else
qDebug() << "File Does not exist";
QBuffer buffer(&byteArray);
qDebug() << buffer.size();

QWidget widget;
QVBoxLayout layout;
Phonon::MediaObject m_MediaObject;
Phonon::VideoWidget *p = new Phonon::VideoWidget(&widget);
//p->focusOutEvent();
p->setContextMenuPolicy(Qt::CustomContextMenu);
widget.setGeometry(100,100,600,600);
layout.addWidget(p);
layout.setContentsMargins(0, 0, 0, 0);
widget.setLayout(&layout);
p->setGeometry(0,0,700,700);
m_MediaObject.setCurrentSource(&buffer);
Phonon::createPath(&m_MediaObject, p);
p->setScaleMode(Phonon::VideoWidget::FitInView);
p->setAspectRatio(Phonon::VideoWidget::AspectRatioAut o);
m_MediaObject.play();
widget.show();

wysota
5th July 2012, 11:58
This example code is used in main thus no variable goes out of scope.

yandi
6th July 2012, 01:44
Hi..Wysota

yes...you correct, I understand now...thanks for your help :) I will change my code