Results 1 to 3 of 3

Thread: Background music

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2011
    Posts
    36
    Thanks
    3
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Background music

    i am beginner for qt
    i want to play background music in my app.i have used phonon api.when i tried to run no error and no music.
    Mainwindow.cpp
    Phonon::MediaObject *mediaObject=new Phonon::MediaObject(this);
    Phonon::AudioOutput *audioOutput=new Phonon::AudioOutput(Phonon::MusicCategory,this);
    Phonon::createPath(mediaObject,audioOutput);
    QString fileName("Kalimba.mp3");
    mediaObject->setCurrentSource(fileName);
    mediaObject->play();
    main.cpp
    QApplication a(argc, argv);
    Q_INIT_RESOURCE(BmiRc);
    MainWindow w;
    w.show();
    return a.exec();
    help me in correction of my app.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Background music

    Please post the full files, using code tags.

  3. #3
    Join Date
    Apr 2011
    Posts
    36
    Thanks
    3
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Background music

    mainwindow.cpp

    Qt Code:
    1. #include "mainwindow.h"
    2. #include <Phonon/MediaObject>
    3. #include <Phonon/AudioOutput>
    4. #include <Phonon/MediaSource>
    5. #include <Phonon/BackendCapabilities>
    6.  
    7. MainWindow::MainWindow(QWidget *parent)
    8. : QMainWindow(parent)
    9. {
    10. qDebug()<<"sample program";
    11. qDebug() << Phonon::BackendCapabilities::availableAudioOutputDevices();
    12.  
    13. Phonon::MediaObject *mediaObject=new Phonon::MediaObject(this);
    14. Phonon::AudioOutput *audioOutput=new Phonon::AudioOutput(Phonon::MusicCategory,this);
    15. Phonon::createPath(mediaObject,audioOutput);
    16. qDebug()<<"playing";
    17. QString fileName("/Kalimba.mp3");
    18. mediaObject->setCurrentSource(fileName);
    19.  
    20. qDebug()<<"played";
    21. connect(mediaObject,SIGNAL(aboutToFinish()),SLOT(close()));
    22. mediaObject->play();
    23. }
    24. void close()
    25. {
    26. qDebug()<<"closed";
    27. }
    28.  
    29. MainWindow::~MainWindow()
    30. {
    31.  
    32. }
    To copy to clipboard, switch view to plain text mode 


    main.cpp


    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. Q_INIT_RESOURCE(rsc3);
    8. a.setApplicationName("Sample Program");
    9. a.setQuitOnLastWindowClosed(true);
    10.  
    11. MainWindow w;
    12. w.show();
    13.  
    14. return a.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 



    output


    sample program
    ("Default DirectSound Device", "DirectSound: Speakers / Headphones (IDT High Definition Audio CODEC)", "Speakers / Headphones (IDT High", "{4672319F-A9E7-4557-B6D3-D375388A529B}", "Default WaveOut Device")
    playing
    played

Similar Threads

  1. Replies: 19
    Last Post: 13th May 2013, 11:17
  2. Phonon Music Player example
    By pssss in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2011, 14:30
  3. UI to preview pictures and music
    By Akira in forum Newbie
    Replies: 5
    Last Post: 16th December 2010, 20:38
  4. playing music from a database
    By Baasie in forum Qt Programming
    Replies: 5
    Last Post: 19th January 2010, 10:48
  5. How to make my app to play background music
    By HelloDan in forum Qt Programming
    Replies: 3
    Last Post: 8th April 2009, 09:17

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
  •  
Qt is a trademark of The Qt Company.