Results 1 to 6 of 6

Thread: playing music from a database

  1. #1
    Join Date
    Aug 2009
    Posts
    29
    Thanked 1 Time in 1 Post

    Default playing music from a database

    Goodday fellow QT'ers, i have searched the forums and internet for my problem but it could not be found.

    First of all what i am trying to achieve:
    I got a music database where it is needed to store the mp3 file into it, i work with a sqlite database. Everything work fine, i can input the files intp the database as blob and also can grab it out of it, store it into a new file and play it.

    But here is what i am trying to do now, when i grab the file from my db i store it in a QByteArray and after put it into an file, but what i want to do is play it directly from that QByteArray wich is possible using QBuffer as i have read in the docs.

    i tried this approach but it does not seem to want to work, here is my code:

    Qt Code:
    1. QSqlQuery blob = dataBase->getQuery("SELECT id_music, data FROM user_getBlob WHERE (id_music=10)");
    2. blob.next();
    3. QByteArray soundByte = blob.value(1).toByteArray();
    4. QCoreApplication::processEvents();
    5. blob.clear();
    6. soundBuffer = new QBuffer(&soundByte);
    7. QCoreApplication::processEvents();
    8. mediaPlayer->mediaObject->setCurrentSource(soundBuffer);
    To copy to clipboard, switch view to plain text mode 

    if i do this i get the following error:

    No combination of filters could be found to render the stream. (0x80040218)

    but here is the odd part, the error is written in my native language wich is dutch (i translated it).. and there is the strange part.

    so does anyone here know what the problem might be, i know the solution is just to store the bytearray into a file and play the file, but if there is a way to make it work like this it would be much better.

    thanx in advance,

    Baasie

  2. #2
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: playing music from a database

    I think you have to call soundBuffer.open(QIODevice::ReadOnly); after creating it. Also, be sure that soundByte is not going out of scope while the buffer is being read.

  3. #3
    Join Date
    Aug 2009
    Posts
    29
    Thanked 1 Time in 1 Post

    Default Re: playing music from a database

    Thank you for your reply,

    it seems that it goes better now only it gives me a QThread::wait: Thread tried to wait on itself.

    My code :


    "Query: SELECT id_music, data FROM user_getBlob WHERE (id_music=35)"

    core class
    Qt Code:
    1. blobString.append("SELECT id_music, data FROM user_getBlob WHERE (id_music="+newMusicModel->musicList.at(charts->rowNewSongIndex()).getID_Music()+")");
    2. QSqlQuery blob = dataBase->getQuery(blobString);
    3. blob.next();
    4. QByteArray soundByte = blob.value(1).toByteArray();
    5. QCoreApplication::processEvents();
    6. blob.clear();
    7. soundBuffer = new QBuffer(&soundByte);
    8. QCoreApplication::processEvents();
    9. mediaPlayer->inputUrl(soundBuffer);
    To copy to clipboard, switch view to plain text mode 

    MediaPlayer class
    Qt Code:
    1. void MediaPlayer::inputUrl(QBuffer *buffer)
    2. {
    3. buffer->open(QIODevice::ReadOnly);
    4. Phonon::MediaSource source(buffer);
    5. mediaObject->stop();
    6. mediaObject->clearQueue();
    7. mediaObject->setCurrentSource(source);
    8. audioOutput->setVolume(0.0);
    9. mediaObject->play();
    10. playTimer = new QTimer(this);
    11. connect(playTimer, SIGNAL(timeout()), this, SLOT(stopped()));
    12. playTimer->start(20000);
    13. emit output("MediaPlayer::inputUrl >> ", "Loaded mp3");
    14. }
    To copy to clipboard, switch view to plain text mode 

    anyone know what this can mean...

    the QTimer is not the problem, i use it only to play just 20s of the son....

    thanx in advance

    p.s. how do you prevent it from not getting out of scope?

  4. #4
    Join Date
    Jul 2009
    Posts
    139
    Thanks
    13
    Thanked 59 Times in 52 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: playing music from a database

    Just create it on the heap:
    Qt Code:
    1. QByteArray * soundByte = new QByteArray(blob.value(1).toByteArray());
    To copy to clipboard, switch view to plain text mode 
    P.S QByteArray uses implicit data sharing so don't worry about having multiple copies.

  5. #5
    Join Date
    Aug 2009
    Posts
    29
    Thanked 1 Time in 1 Post

    Cool Re: playing music from a database

    Never thought about doing it like that,

    BUT thanx A LOT it works perfectly

    case closed ....

  6. #6
    Join Date
    Aug 2009
    Posts
    29
    Thanked 1 Time in 1 Post

    Default Re: playing music from a database

    okey case not close ...

    it has been wroking great but i checked the internal memory use of my program and everytime it call this function:

    Qt Code:
    1. QSqlQuery blob = dataBase.getQuery("SELECT id_music, data FROM user_getBlob WHERE (id_music="+selectedAlbumModel.selectedAlbumList.at(index.row()).getID_Music()+")");
    2. blob.next();
    3. QByteArray * soundByte = new QByteArray(blob.value(1).toByteArray());
    4. blob.clear();
    5. soundBuffer = new QBuffer(soundByte);
    6. mediaPlayer.inputUrl(soundBuffer);
    To copy to clipboard, switch view to plain text mode 

    it extends the internal memory use of the program... anyone has any clue how this is possible?

    thanx in advance

Similar Threads

  1. Do you listen music while programming?
    By Raccoon29 in forum General Discussion
    Replies: 20
    Last Post: 30th January 2011, 09:49
  2. Replies: 1
    Last Post: 14th September 2009, 09:48
  3. problem with phonon/music player example.
    By rishiraj in forum Newbie
    Replies: 9
    Last Post: 23rd January 2009, 09:00
  4. Qt for iTouch-like 3D wheel music browser?
    By joanna in forum Qt Programming
    Replies: 2
    Last Post: 5th September 2008, 19:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.