From b8b6d3cbb32801fed87052e60fce73ea24cc684d Mon Sep 17 00:00:00 2001 From: Salanto Date: Wed, 5 May 2021 00:42:48 +0200 Subject: [PATCH] Add musclist streaming support Attempt Nr. 2 - Based on #548 and #501 + Allows client to use a remote source as a last resort if the file can't be found locally. + Adds a check if the target file is missing. This implementation assumed the streaming source to be structured like a webao content respository --- include/aomusicplayer.h | 2 +- src/aomusicplayer.cpp | 5 +++-- src/courtroom.cpp | 30 ++++++++++++++++++++++-------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/include/aomusicplayer.h b/include/aomusicplayer.h index 36031f1..f899b9a 100644 --- a/include/aomusicplayer.h +++ b/include/aomusicplayer.h @@ -25,7 +25,7 @@ public: int loop_end[4] = {0, 0, 0, 0}; public slots: - void play(QString p_song, int channel = 0, bool loop = false, + int play(QString p_song, int channel = 0, bool loop = false, int effect_flags = 0); void stop(int channel = 0); diff --git a/src/aomusicplayer.cpp b/src/aomusicplayer.cpp index 8a3142e..e8bd690 100644 --- a/src/aomusicplayer.cpp +++ b/src/aomusicplayer.cpp @@ -13,12 +13,12 @@ AOMusicPlayer::~AOMusicPlayer() } } -void AOMusicPlayer::play(QString p_song, int channel, bool loop, +int AOMusicPlayer::play(QString p_song, int channel, bool loop, int effect_flags) { channel = channel % m_channelmax; if (channel < 0) // wtf? - return; + return BASS_ERROR_NOCHAN; QString f_path = ao_app->get_music_path(p_song); unsigned int flags = BASS_STREAM_PRESCAN | BASS_STREAM_AUTOFREE | @@ -125,6 +125,7 @@ void AOMusicPlayer::play(QString p_song, int channel, bool loop, this->set_looping(loop, channel); // Have to do this here due to any // crossfading-related changes, etc. + return BASS_ErrorGetCode(); } void AOMusicPlayer::stop(int channel) diff --git a/src/courtroom.cpp b/src/courtroom.cpp index 82b98e3..a2dca89 100644 --- a/src/courtroom.cpp +++ b/src/courtroom.cpp @@ -3824,6 +3824,11 @@ void Courtroom::handle_song(QStringList *p_contents) return; } + if(!file_exists(ao_app->get_sfx_suffix(ao_app->get_music_path(f_song))) && !f_song.startsWith("http") + && f_song != "~stop.mp3" && ao_app->asset_url != NULL) { + f_song = (ao_app->asset_url + "sounds/music/" + f_song).toLower(); + } + bool is_stop = (f_song == "~stop.mp3"); if (n_char >= 0 && n_char < char_list.size()) { QString str_char = char_list.at(n_char).name; @@ -3845,17 +3850,26 @@ void Courtroom::handle_song(QStringList *p_contents) } } - music_player->play(f_song, channel, looping, effect_flags); + int error_code = music_player->play(f_song, channel, looping, effect_flags); + if (is_stop) { ui_music_name->setText(tr("None")); + return; } - else if (channel == 0) { - if (file_exists(ao_app->get_sfx_suffix(ao_app->get_music_path(f_song))) && !f_song.startsWith("http")) - ui_music_name->setText(f_song_clear); - else if (f_song.startsWith("http")) - ui_music_name->setText(tr("[STREAM] %1").arg(f_song_clear)); - else - ui_music_name->setText(tr("[MISSING] %1").arg(f_song_clear)); + + if (error_code == BASS_ERROR_HANDLE) { // Cheap hack to see if file missing + ui_music_name->setText(tr("[MISSING] %1").arg(f_song_clear)); + return; + } + + if (f_song.startsWith("http") && channel == 0) { + ui_music_name->setText(tr("[STREAM] %1").arg(f_song_clear)); + return; + } + + if (channel == 0){ + ui_music_name->setText(f_song_clear); + return; } }