Results 1 to 3 of 3

Thread: Why use QAudioOutput play audio is fail?

  1. #1
    Join Date
    Apr 2016
    Posts
    37
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Why use QAudioOutput play audio is fail?

    hi , all.

    i use QAudioInput record sound.

    input code is :
    Qt Code:
    1. void start(){
    2. file = new QFile("C:/audiorecord.raw");
    3. file->open(QIODevice::WriteOnly | QIODevice::Truncate);
    4. //set format
    5. QAudioFormat format;
    6. format.setSampleRate(8000);
    7. format.setChannelCount(1);
    8. format.setSampleSize(32);
    9. format.setCodec("audio/pcm");
    10. format.setByteOrder(QAudioFormat::LittleEndian);
    11. format.setSampleType(QAudioFormat::Float);
    12.  
    13. input = new QAudioInput(format, this);//input is QAudioInput * input;
    14. input->start(file);
    15. }
    16.  
    17. void finish(){
    18. input->stop();
    19. file->close();
    20. }
    To copy to clipboard, switch view to plain text mode 

    write data to successful , call function "void finish()" later.

    Qt Code:
    1. void play(){
    2. file->setFileName("C:/audiorecord.raw");
    3. file->open(QIODevice::ReadOnly);
    4.  
    5. QAudioFormat format;
    6. format.setSampleRate(8000);
    7. format.setChannelCount(1);
    8. format.setSampleSize(32);
    9. format.setCodec("audio/pcm");
    10. format.setByteOrder(QAudioFormat::LittleEndian);
    11. format.setSampleType(QAudioFormat::Float);
    12.  
    13. output = new QAudioOutput(format,0);
    14. output->start(file);
    15. }
    To copy to clipboard, switch view to plain text mode 

    if the program not restarted , in "start()" later call function "play()" is no problem, Play success.

    but if program restarted , call play() is program crash.

    What's the problem?

    I will very much appreciate it.

  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: Why use QAudioOutput play audio is fail?

    play() accesses "file" without checking it is a valid pointer.
    start() creates the file, so play() works after start().

    Cheers,
    _

  3. #3
    Join Date
    Apr 2016
    Posts
    37
    Thanks
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Why use QAudioOutput play audio is fail?

    Quote Originally Posted by anda_skoa View Post
    play() accesses "file" without checking it is a valid pointer.
    start() creates the file, so play() works after start().

    Cheers,
    _
    thank you.

    oh!!! sorry , a very stupid mistake , I was too careless.

Similar Threads

  1. Using QAudioOutput to play sounds for a metronome
    By tcampos in forum Qt Programming
    Replies: 3
    Last Post: 8th March 2012, 19:57
  2. How to flush audio buffers controlled by QAudioOutput?
    By hackerNovitiate in forum Newbie
    Replies: 0
    Last Post: 20th January 2012, 01:06
  3. QaudioOutPut Stream Audio In Chat Voice ?
    By Thành Viên Mới in forum Qt Programming
    Replies: 2
    Last Post: 17th June 2011, 03:33
  4. QAudioOutput Play Audio Buffer chat voice ?
    By Thành Viên Mới in forum Qt Programming
    Replies: 5
    Last Post: 11th May 2011, 19:35
  5. QaudioOutput play buffer audio real time disconnect network ?
    By Thành Viên Mới in forum Qt Programming
    Replies: 1
    Last Post: 10th May 2011, 12:20

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.