How can I use Qt to encrypt/decrypte/play a video? -


i looking way encrypt video file , use decrypt ram , play directly.

setmedia takes qiodevice second argument:

  #include <qmediaplayer>   #include <qapplication>   #include <qfile>   int main(int argc, char ** argv)   {       qapplication app(argc,argv);       qstring filename = app.arguments().at(1);        qfile io(filename);       io.open(qfile::readonly);        qmediaplayer player;        player.setmedia(qurl("test.mp3"), &io);       player.play();        return app.exec();   } 

but in case really mean qdatastream:

qdatastream buffered io, qiodevice direct io, they're not compatible, have double buffer this:

#include <qmediaplayer> #include <qapplication> #include <qfile> #include <qbuffer> #include <qdatastream> int main(int argc, char ** argv) {     qapplication app(argc,argv);     qstring filename = app.arguments().at(1);      // our double buffer     qbytearray bufferspace;      // our stream on can put "media" data     qdatastream stream(&bufferspace, qiodevice::writeonly);      // demo data     qfile io(filename);     io.open(qfile::readonly);     stream << io.readall();      // open io device on our buffer     qbuffer buffer(&bufferspace);     buffer.open(qbuffer::readonly);      // give io media player     qmediaplayer player;     player.setmedia(qurl("test.mp3"), &buffer);     player.play();      return app.exec(); } 

edit

here's faster version of "crypto" code posted without using buffer entire file:

#include <qmediaplayer> #include <qapplication> #include <qfile> #include <qbuffer> #include <qdatastream>  static const unsigned char key = 0xab; class myfunnycrypto : public qfile /*or subclass other io*/ { protected:     virtual qint64 readdata(char *data, qint64 maxsize)     {         qint64 r = qfile::readdata(data, maxsize);         if (r > 0) {             (qint64 = 0; < r; i++) {                 data[i] = data[i]^key;             }         }         return r;     }  };   int main(int argc, char ** argv) {     qapplication app(argc,argv);     qstring filename = app.arguments().at(1);       myfunnycrypto io;     io.setfilename(filename);     io.open(qfile::readonly);      // give io media player     qmediaplayer player;     player.setmedia(qurl("test.mp3"), &io);     player.play();      return app.exec(); } 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -