mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-12 01:38:37 +12:00
cellMusic: Fix resume, fast forward and rewind
- Sadly rewind does not work with the QMediaPlayer on windows
This commit is contained in:
parent
577f379a12
commit
d80146c704
7 changed files with 198 additions and 156 deletions
|
@ -15,7 +15,33 @@ qt_music_handler::qt_music_handler()
|
|||
m_media_player = std::make_shared<QMediaPlayer>();
|
||||
m_media_player->setAudioRole(QAudio::Role::MusicRole);
|
||||
|
||||
m_error_handler = std::make_unique<qt_music_error_handler>(m_media_player);
|
||||
m_error_handler = std::make_unique<qt_music_error_handler>(m_media_player,
|
||||
[this](QMediaPlayer::MediaStatus status)
|
||||
{
|
||||
if (!m_status_callback)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (status)
|
||||
{
|
||||
case QMediaPlayer::MediaStatus::UnknownMediaStatus:
|
||||
case QMediaPlayer::MediaStatus::NoMedia:
|
||||
case QMediaPlayer::MediaStatus::LoadingMedia:
|
||||
case QMediaPlayer::MediaStatus::LoadedMedia:
|
||||
case QMediaPlayer::MediaStatus::StalledMedia:
|
||||
case QMediaPlayer::MediaStatus::BufferingMedia:
|
||||
case QMediaPlayer::MediaStatus::BufferedMedia:
|
||||
case QMediaPlayer::MediaStatus::InvalidMedia:
|
||||
break;
|
||||
case QMediaPlayer::MediaStatus::EndOfMedia:
|
||||
m_status_callback(player_status::end_of_media);
|
||||
break;
|
||||
default:
|
||||
music_log.error("Ignoring unknown status %d", static_cast<int>(status));
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
qt_music_handler::~qt_music_handler()
|
||||
|
@ -29,29 +55,6 @@ qt_music_handler::~qt_music_handler()
|
|||
});
|
||||
}
|
||||
|
||||
void qt_music_handler::play(const std::string& path)
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
|
||||
Emu.BlockingCallFromMainThread([&path, this]()
|
||||
{
|
||||
if (m_state == CELL_MUSIC_PB_STATUS_PAUSE)
|
||||
{
|
||||
music_log.notice("Resuming music: %s", path);
|
||||
}
|
||||
else
|
||||
{
|
||||
music_log.notice("Playing music: %s", path);
|
||||
m_media_player->setPlaybackRate(1.0);
|
||||
m_media_player->setMedia(QUrl(QString::fromStdString(path)));
|
||||
}
|
||||
|
||||
m_media_player->play();
|
||||
});
|
||||
|
||||
m_state = CELL_MUSIC_PB_STATUS_PLAY;
|
||||
}
|
||||
|
||||
void qt_music_handler::stop()
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
|
@ -78,27 +81,61 @@ void qt_music_handler::pause()
|
|||
m_state = CELL_MUSIC_PB_STATUS_PAUSE;
|
||||
}
|
||||
|
||||
void qt_music_handler::fast_forward()
|
||||
void qt_music_handler::play(const std::string& path)
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
|
||||
Emu.BlockingCallFromMainThread([this]()
|
||||
Emu.BlockingCallFromMainThread([&path, this]()
|
||||
{
|
||||
if (m_path != path)
|
||||
{
|
||||
m_path = path;
|
||||
m_media_player->setMedia(QUrl(QString::fromStdString(path)));
|
||||
}
|
||||
|
||||
music_log.notice("Playing music: %s", path);
|
||||
m_media_player->setPlaybackRate(1.0);
|
||||
m_media_player->play();
|
||||
});
|
||||
|
||||
m_state = CELL_MUSIC_PB_STATUS_PLAY;
|
||||
}
|
||||
|
||||
void qt_music_handler::fast_forward(const std::string& path)
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
|
||||
Emu.BlockingCallFromMainThread([&path, this]()
|
||||
{
|
||||
if (m_path != path)
|
||||
{
|
||||
m_path = path;
|
||||
m_media_player->setMedia(QUrl(QString::fromStdString(path)));
|
||||
}
|
||||
|
||||
music_log.notice("Fast-forwarding music...");
|
||||
m_media_player->setPlaybackRate(2.0);
|
||||
m_media_player->play();
|
||||
});
|
||||
|
||||
m_state = CELL_MUSIC_PB_STATUS_FASTFORWARD;
|
||||
}
|
||||
|
||||
void qt_music_handler::fast_reverse()
|
||||
void qt_music_handler::fast_reverse(const std::string& path)
|
||||
{
|
||||
std::lock_guard lock(m_mutex);
|
||||
|
||||
Emu.BlockingCallFromMainThread([this]()
|
||||
Emu.BlockingCallFromMainThread([&path, this]()
|
||||
{
|
||||
if (m_path != path)
|
||||
{
|
||||
m_path = path;
|
||||
m_media_player->setMedia(QUrl(QString::fromStdString(path)));
|
||||
}
|
||||
|
||||
music_log.notice("Fast-reversing music...");
|
||||
m_media_player->setPlaybackRate(-2.0);
|
||||
m_media_player->play();
|
||||
});
|
||||
|
||||
m_state = CELL_MUSIC_PB_STATUS_FASTREVERSE;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue