Results 1 to 3 of 3

Thread: Breaking out of QMediaPlaylist with setPlaybackMode set to inf loop

  1. #1
    Join Date
    May 2014
    Posts
    4
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Breaking out of QMediaPlaylist with setPlaybackMode set to inf loop

    Hi everyone,

    Is this possible?

    Im trying:
    Qt Code:
    1. bool MainWindow::on_checkBox_clicked()
    2. {
    3.  
    4.  
    5. QString alarmTime = QString::number(this->ui->timeEdit->time().hour()) + QString::number(this->ui->timeEdit->time().minute());
    6. QString currentTime = QString::number(QTime::currentTime().hour()) + QString::number(QTime::currentTime().minute());
    7.  
    8. QMediaPlaylist *playlist = new QMediaPlaylist(this);
    9. playlist->addMedia(QUrl::fromLocalFile("/path/song.mp3"));
    10. playlist->setPlaybackMode(QMediaPlaylist::Loop);
    11. playlist->setCurrentIndex(1);
    12. QMediaPlayer *player = new QMediaPlayer(this);
    13. player->setPlaylist(playlist);
    14. player->setVolume(100);
    15.  
    16. if(this->ui->checkBox_2->isChecked() == false)
    17. {
    18. if(alarmTime == currentTime)
    19. {
    20. player->play();
    21. }
    22. }
    23. else
    24. if(this->ui->checkBox_2->isChecked() == true)
    25. {
    26. playlist->stop();
    27. }
    28.  
    29. }
    To copy to clipboard, switch view to plain text mode 

    It starts playing fine, but when I click the appropriate check box to stop it, it does not. Any thoughts on how I can get this to work properly?

    Thank you!!!

  2. #2
    Join Date
    Oct 2013
    Posts
    41
    Thanks
    1
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Breaking out of QMediaPlaylist with setPlaybackMode set to inf loop

    Maybe I'm understanding this wrong but it looks like you're creating a new player/playlist each time you click, and you actually want to stop the player from the last or first click. Maybe use a global player, or at least point to one?

  3. #3
    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: Breaking out of QMediaPlaylist with setPlaybackMode set to inf loop

    Indeed.

    Let playlist be a member of MainWindow and in the slot you just call play() or stop(), depending on the checkbox's state.

    Cheers,
    _

Similar Threads

  1. How to add QMediaPlaylist to a layout
    By adutzu89 in forum Newbie
    Replies: 2
    Last Post: 2nd December 2013, 08:06
  2. QMediaPlaylist view
    By Festus Hagen in forum Qt Programming
    Replies: 0
    Last Post: 6th September 2013, 07:23
  3. Replies: 2
    Last Post: 11th October 2011, 14:55
  4. Qt Designer Problem moving widget after breaking layout
    By nickolais in forum Qt Tools
    Replies: 0
    Last Post: 10th June 2010, 22:21
  5. NEED HELP: How to download file without breaking function
    By codeslicer in forum Qt Programming
    Replies: 10
    Last Post: 22nd April 2008, 04:10

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.