[Interest] Setting the Volume of QMediaPlayer conflict

Jason Kretzer Jason at gocodigo.com
Mon Sep 22 21:45:21 CEST 2014


Hello all,

I am using the code below to instantiate two QMediaPlayer instances.  I want the first one to play at a lower volume than the second.  So, I set each volume accordingly, the first player to 1 and the second player to 95.  However, they both end up playing at the same volume (95).  If I remove the second player, the first player will play at a low level as it is supposed to.  Adding the in the second block however adjusts both.  The two qdebug statements at the end contradict what happens though as it shows that each volume is set appropriately, though if you listen it is obviously not the case.  Is there a trick that I am missing?  Thanks!

Qt 5.3.1, Win 7, VS2010
    

QMediaPlayer *player = new QMediaPlayer;
    player->setMedia(QUrl::fromLocalFile("C:/Users/jasonkretzer/Desktop/audio/whippedintoshape.mp3"));
    player->setVolume(1);
    player->play();

    qDebug() << "player volume: " << player->volume();

    QMediaPlayer *player2 = new QMediaPlayer;
    player2->setMedia(QUrl::fromLocalFile("C:/Users/jasonkretzer/Desktop/audio/1to20.m4a"));
    player2->setVolume(95);
    player2->play();

    qDebug() << "player volume: " << player->volume();
    qDebug() << "player2 volume: " << player2->volume();



More information about the Interest mailing list