×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    41

    Sound not working

    I am developing a game that contains many sounds
    but the sound is not working
    i am using this code

    .pro
    CONFIG += mobility
    MOBILITY += multimedia
    Header
    #include <qmediaplayer.h>
    #include <qmediaplaylist.h>

    private slots:
    void statusChanged(QMediaPlayer::MediaStatus status);
    private:
    QMediaPlayer *player;
    QMediaPlaylist *playlist;

    .cpp

    #include <qurl.h>


    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);




    player = new QMediaPlayer(this);
    player->setVolume(50); // set Volume
    playlist = new QMediaPlaylist(this);
    playlist->setMediaObject(player);

    connect(player, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)),
    this, SLOT(statusChanged(QMediaPlayer::MediaStatus)));

    playlist->addMedia(QUrl::fromLocalFile("c:\\test.mp3")); // you can add as many media files as you want

    player->play();


    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }
    void MainWindow::statusChanged(QMediaPlayer::MediaStatus status) {
    switch (status) {
    case QMediaPlayer::LoadedMedia:
    player->play();
    break;
    default:
    break;
    }
    }

    i got this code from this link:
    http://wiki.forum.nokia.com/index.ph...ng_Qt_Mobility


    error is:
    virtual bool QMediaPlaylist::setMediaObject(QMediaObject *object) is protected
    within the context



    please help

  2. #2
    Regular Contributor
    Join Date
    May 2010
    Posts
    362

    Re: Sound not working

    You can simply use QSound:lay("myfile.wav"); to play the sound?
    It should support mp3.

    There might be slight delay and in some cases doing it this way is not recommended, but for simple game it should be more than usable.
    After all, you could change the implementation later on, but atleast continue your development now and change to something else later if this is not enough for you.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    41

    Re: Sound not working

    teemup when i used QSound i heard a sound like error sound in windows xp , the sound is mp3 format ... its not working

  4. #4
    Registered User
    Join Date
    Jul 2004
    Posts
    166

    Re: Sound not working

    I remembered reading it somewhere that QSound works only with .wav file. I also have tried playing sound with QSound but I failed and then i switched to phonon.

    but can you try this simpler version.

    QMediaPlayer *player = new QMediaPlayer;
    player->setMedia(QUrl::fromLocalFile("test.raw"));
    player->setVolume(50);
    player->play();
    http://kunalmaemo.blogspot.com/

  5. #5
    Registered User
    Join Date
    Nov 2010
    Posts
    41

    Re: Sound not working

    its also not working:s

    i also tried to use phonon but i donot know how its work , can u help me inorder to switch to phonon .

  6. #6
    Super Contributor
    Join Date
    Oct 2008
    Location
    INDIA
    Posts
    2,326

    Re: Sound not working

    Quote Originally Posted by wehbi View Post
    its also not working:s

    i also tried to use phonon but i donot know how its work , can u help me inorder to switch to phonon .
    Phonon was the old module,,,,,
    Now You have to use Qt Multimedia API under Qt Mobility......

    See this example here .mp3 file is working : http://wiki.forum.nokia.com/index.ph...ng_Qt_Mobility

    best regards,

  7. #7
    Registered User
    Join Date
    Nov 2010
    Posts
    41

    Re: Sound not working

    Quote Originally Posted by rahulvala View Post
    Phonon was the old module,,,,,
    Now You have to use Qt Multimedia API under Qt Mobility......

    See this example here .mp3 file is working : http://wiki.forum.nokia.com/index.ph...ng_Qt_Mobility

    best regards,

    rahulvala i used QT Multimedia Api but i got this error:
    virtual bool QMediaPlaylist::setMediaObject(QMediaObject *object) is protected
    within the context
    have u used this code before? , please if u have the correct code help me .
    Thank u

  8. #8
    Super Contributor
    Join Date
    Oct 2008
    Location
    INDIA
    Posts
    2,326

    Re: Sound not working

    Have you gone through the article ,I suggested to you ?

    By the way,,,Show us the code and your .pro file ?
    So that we can help better ?

  9. #9
    Registered User
    Join Date
    Jul 2004
    Posts
    166

    Re: Sound not working

    following is simple code to play sound using phonon.

    Phonon::MediaObject *music =
    Phonon::createPlayer(Phonon::MusicCategory,
    Phonon::MediaSource("/path/mysong.mp3"));
    music->play();

    add following in pro file
    QT += phonon
    http://kunalmaemo.blogspot.com/

  10. #10
    Super Contributor
    Join Date
    Jul 2008
    Posts
    2,020

    Re: Sound not working

    Hello,
    sorry for my late reply.

    If you can live with a bit of Symbian-only code in your app, this snippet will work perfectly:
    http://tamss60.tamoggemon.com/2010/0...t-for-symbian/
    The lines above are the best I have to offer.If anyone of you is of more advanced knowledge, I ask for your patience and understanding! - unknown arab poet
    http://www.tamoggemon.com - Symbian blog - Windows Phone blog
    My other blogs:
    webOS blog iPhone blog BlackBerry blog Samsung bada blog Android blog

  11. #11
    Registered User
    Join Date
    Nov 2010
    Posts
    41

    Re: Sound not working

    thanks its working , what i do is i used phonon
    before it doesnt work because i tested application in a simulater , but when tested the it in a desktop its working.

    but i face another issue , how to play the sound in a continuous playback until i decide to stop or pause, because in the game the sound sho always repeated.

  12. #12
    Registered User
    Join Date
    Jul 2004
    Posts
    166

    Re: Sound not working

    one solution might be, you can listen to finished signal from MediaObject and as soon as you get finished signal, you can put request to play again. There is also aboutToFinish signal, you might try using this as well.
    http://kunalmaemo.blogspot.com/

  13. #13
    Registered User
    Join Date
    Jun 2007
    Location
    Mumbai, India
    Posts
    1,998

    Re: Sound not working

    You can observe the status of the media being played and run it in a loop.

  14. #14
    Registered User
    Join Date
    Nov 2010
    Posts
    41

    Re: Sound not working

    thank u kunal i got the idea , its the best way to listen to the finish signal and replay the sound .

  15. #15
    Registered User
    Join Date
    Jul 2004
    Posts
    166

    Re: Sound not working

    welcome
    http://kunalmaemo.blogspot.com/

Similar Threads

  1. playing a sound not working
    By gnanasenthil654321 in forum Symbian
    Replies: 1
    Last Post: 2008-11-24, 07:30
  2. No sound working on 6600 problem..
    By johan_olsson76 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2003-11-19, 15:30
  3. Sound.init on N7650 working?
    By polyphemus in forum Mobile Java General
    Replies: 1
    Last Post: 2002-11-28, 02:09
  4. recording is not working in sound example
    By amitagrawal78 in forum Symbian
    Replies: 1
    Last Post: 2002-10-08, 11:08
  5. recording is not working in sound example
    By amitagrawal78 in forum Symbian User Interface
    Replies: 0
    Last Post: 2002-10-08, 10:21

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×