diff options
| author | oldmud0 <oldmud0@users.noreply.github.com> | 2021-12-30 20:31:44 -0600 |
|---|---|---|
| committer | oldmud0 <oldmud0@users.noreply.github.com> | 2021-12-30 20:31:44 -0600 |
| commit | ee76c2ce61f6996bfae3ef027eaee8485d455c95 (patch) | |
| tree | c70e266cad00d0adf27be8fa51a07e13de9828db /src/aomusicplayer.cpp | |
| parent | ecfb791e483234308b1edacb87e499860a63e510 (diff) | |
| parent | 593bd54000be14c9a1455914285c1b2549b0fa51 (diff) | |
Merge branch 'master' into feature/http-ms
# Conflicts:
# src/networkmanager.cpp
Diffstat (limited to 'src/aomusicplayer.cpp')
| -rw-r--r-- | src/aomusicplayer.cpp | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/src/aomusicplayer.cpp b/src/aomusicplayer.cpp index d0d95635..16d6df7a 100644 --- a/src/aomusicplayer.cpp +++ b/src/aomusicplayer.cpp @@ -13,12 +13,13 @@ AOMusicPlayer::~AOMusicPlayer() } } -int AOMusicPlayer::play(QString p_song, int channel, bool loop, +QString AOMusicPlayer::play(QString p_song, int channel, bool loop, int effect_flags) { + QFuture<QString> invoking_future = music_watcher.future(); channel = channel % m_channelmax; if (channel < 0) // wtf? - return BASS_ERROR_NOCHAN; + return "[ERROR] Invalid Channel"; QString f_path = ao_app->get_real_path(ao_app->get_music_path(p_song)); unsigned int flags = BASS_STREAM_PRESCAN | BASS_STREAM_AUTOFREE | @@ -43,6 +44,14 @@ int AOMusicPlayer::play(QString p_song, int channel, bool loop, newstream = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, flags); } + int error_code = BASS_ErrorGetCode(); + + if (invoking_future.isCanceled() && channel == 0) { + // Target future has changed. This stream has become irrelevant. + // So even if the stream manages to finish after the latest one, we don't run + // into order issues. + return QString(); + } if (ao_app->get_audio_output_device() != "default") BASS_ChannelSetDevice(m_stream_list[channel], BASS_GetDevice()); @@ -109,7 +118,7 @@ int AOMusicPlayer::play(QString p_song, int channel, bool loop, BASS_ChannelStop(m_stream_list[channel]); m_stream_list[channel] = newstream; - BASS_ChannelPlay(m_stream_list[channel], false); + BASS_ChannelPlay(newstream, false); if (effect_flags & FADE_IN) { // Fade in our sample BASS_ChannelSetAttribute(newstream, BASS_ATTRIB_VOL, 0); @@ -120,12 +129,32 @@ int AOMusicPlayer::play(QString p_song, int channel, bool loop, else this->set_volume(m_volume[channel], channel); - BASS_ChannelSetSync(m_stream_list[channel], BASS_SYNC_DEV_FAIL, 0, + BASS_ChannelSetSync(newstream, BASS_SYNC_DEV_FAIL, 0, ao_app->BASSreset, 0); this->set_looping(loop, channel); // Have to do this here due to any // crossfading-related changes, etc. - return BASS_ErrorGetCode(); + + bool is_stop = (p_song == "~stop.mp3"); + QString p_song_clear = QUrl(p_song).fileName(); + p_song_clear = p_song_clear.left(p_song_clear.lastIndexOf('.')); + + if (is_stop) { + return QObject::tr("None"); + } + + if (error_code == BASS_ERROR_HANDLE) { // Cheap hack to see if file missing + return QObject::tr("[MISSING] %1").arg(p_song_clear); + } + + if (p_song.startsWith("http") && channel == 0) { + return QObject::tr("[STREAM] %1").arg(p_song_clear); + } + + if (channel == 0) + return p_song_clear; + + return ""; } void AOMusicPlayer::stop(int channel) |
