Results 1 to 4 of 4

Thread: problem with save mp3 with QNetworkReply

  1. #1
    Join Date
    Feb 2014
    Posts
    6
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default problem with save mp3 with QNetworkReply

    i want safe mp3 stream to file

    void Main::reply_readyReadSlot()
    {
    //buff its QBuffer;
    buff.write(reply->readLine());

    }

    always destination file lost ~5% of headers, you can look this file this.
    maybe need writing buffer in other place?
    Last edited by azazaz; 15th June 2016 at 17:08.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: problem with save mp3 with QNetworkReply

    readLine(), reads, as it says, a line. So until an "end of line" character.
    If your data is mp3 data, then it is not text, so you shouldn't be treating it like text.

    If your want to read all data that is available at this point, use readAll()

    Cheers,
    _

  3. #3
    Join Date
    Feb 2014
    Posts
    6
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: problem with save mp3 with QNetworkReply

    Quote Originally Posted by anda_skoa View Post
    readLine(), reads, as it says, a line. So until an "end of line" character.
    If your data is mp3 data, then it is not text, so you shouldn't be treating it like text.

    If your want to read all data that is available at this point, use readAll()

    Cheers,
    _
    Qt Code:
    1. char buffer[2048];
    2. qint64 size = reply->read(buffer, sizeof(buffer));
    3. buf.write(buffer, size);
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. qa=reply->readAll();
    2. buf.write(qa.data(),qa.size() );
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. qa = reply->read(16 * 1024);
    2. buf.write(qa.data(),qa.size());
    3. mp3file.writeRawData(qa.data() ,qa.size());
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void MainWindow::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
    2. {
    3. qa = reply->read(bytesReceived);
    4. buf.write(qa.data(),qa.size());
    5. mp3file.writeRawData(qa.data() ,qa.size());
    6.  
    7. }
    To copy to clipboard, switch view to plain text mode 
    no difference,always mp3 data broken
    but writing mp3 from static files(from url) goes well!
    Last edited by azazaz; 16th June 2016 at 02:36.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: problem with save mp3 with QNetworkReply

    Since the device you are reading from seems to be a QNetworkReply, are you sure the data is just the MP3 data, not including HTML, etc?

    Cheers,
    _

Similar Threads

  1. Replies: 13
    Last Post: 9th March 2016, 11:21
  2. Problem with QNetworkReply::abort()
    By themagician in forum Newbie
    Replies: 1
    Last Post: 5th June 2015, 21:27
  3. QNetworkReply and "unknown error" problem
    By hybrid_snyper in forum Newbie
    Replies: 3
    Last Post: 3rd December 2012, 00:45
  4. QNetworkReply::deleteLater problem
    By TorAn in forum Qt Programming
    Replies: 5
    Last Post: 29th August 2010, 22:17
  5. Replies: 10
    Last Post: 14th January 2010, 23:55

Tags for this Thread

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.