PDA

View Full Version : set raw data buffer to QMediaPlayer



saman_artorious
19th August 2013, 12:46
I want to get a screen shot of the widget application and then set its raw data buffer to QMeidaPlayer with setMedia(). If anyone tried this before, I would thank if you tell me how to do that:



QPixmap originalPixmap = QPixmap::grabWidget(this);

QImage *image = new QImage(originalPixmap.toImage());

QByteArray ba;

QBuffer buffer(&ba);

buffer.setBuffer(&ba);

buffer.open(QIODevice::WriteOnly);

image->save(&buffer); // writes image into ba in PNG format

image->save("/home/saman/Desktop/myImage", "PNG");

mediaPlayer.setMedia(QUrl::fromLocalFile("/home/saman/Desktop/png/images08.jpeg")); //I want this to read from raw data

mediaPlayer.play();


I note again, what i have done is to receive the image, SAVE it, and then read from it. However, I would like to ask you how to read raw data directly without saving it into media player.


// saving
counter = 1;
image.save("/home/saman/image", "JPG");
counter = 0;


somewhere else, reading


if(counter == 0)
{
mediaPlayer.setMedia(QUrl::fromLocalFile("/home/saman/image"));
mediaPlayer.play();
}

saman_artorious
20th August 2013, 09:13
I want to get a screen shot of the widget application and then set its raw data buffer to QMeidaPlayer with setMedia(). If anyone tried this before, I would thank if you tell me how to do that:



QPixmap originalPixmap = QPixmap::grabWidget(this);

QImage *image = new QImage(originalPixmap.toImage());

QByteArray ba;

QBuffer buffer(&ba);

buffer.setBuffer(&ba);

buffer.open(QIODevice::WriteOnly);

image->save(&buffer); // writes image into ba in PNG format

image->save("/home/saman/Desktop/myImage", "PNG");

mediaPlayer.setMedia(QUrl::fromLocalFile("/home/saman/Desktop/png/images08.jpeg")); //I want this to read from raw data

mediaPlayer.play();


I note again, what i have done is to receive the image, SAVE it, and then read from it. However, I would like to ask you how to read raw data directly without saving it into media player.


// saving
counter = 1;
image.save("/home/saman/image", "JPG");
counter = 0;


somewhere else, reading


if(counter == 0)
{
mediaPlayer.setMedia(QUrl::fromLocalFile("/home/saman/image"));
mediaPlayer.play();
}


What I did is to use:


QMediaResource rsrc(QUrl::fromUserInput(image.text()));
QMediaContent ctnt(rsrc);
mediaPlayer.setMedia(ctnt);
mediaPlayer.play();

but this, does not show anything. I need help over here, give me advice please.