/** * \brief Plays a music with an optional Lua callback to call when it finishes. * \param music_id Id of the music to play (file name without extension). * \param loop Whether the music should loop when reaching its end * (if there is an end). * \param callback_ref Lua function to call when the music finishes or * an empty ref. There cannot be both a loop and a callback at the same time. */ void Music::play( const std::string& music_id, bool loop, const ScopedLuaRef& callback_ref ) { if (music_id != unchanged && music_id != get_current_music_id()) { // The music is changed. if (current_music != nullptr) { // Stop the music that was played. current_music->stop(); current_music = nullptr; } if (music_id != none) { // Play another music. current_music = std::unique_ptr<Music>( new Music(music_id, loop, callback_ref) ); if (!current_music->start()) { // Could not play the music. current_music = nullptr; } } } }
/** * @brief Plays a music. * * If the music is different from the current one, * the current one is stopped. * The music specified can also be Music::none_id (then the current music is just stopped) * or even Music::unchanged_id (nothing is done in this case). * * @param music_id id of the music to play (file name without extension) */ void Music::play(const std::string& music_id) { if (music_id != unchanged && music_id != get_current_music_id()) { // the music is changed if (music_id == none && current_music != NULL) { current_music->stop(); current_music = NULL; } else { // play another music if (current_music != NULL) { current_music->stop(); } if (all_musics.count(music_id) == 0) { all_musics[music_id] = Music(music_id); } Music& music = all_musics[music_id]; if (music.start()) { current_music = &music; } else { current_music = NULL; } } } }
/** * @brief Returns whether a music is currently playing. * @param quest The quest. * @return @c true if a music is currently playing. */ bool is_playing_music(const Quest& quest) { return !get_current_music_id(quest).isEmpty(); }
/** * @brief Returns whether a specific music is currently playing. * @param quest The quest. * @param music_id Id of the music to test. * @return @c true if this music is currently playing. */ bool is_playing_music(const Quest& quest, const QString& music_id) { return get_current_music_id(quest) == music_id; }
JNIEXPORT short JNICALL Java_com_technegames_insectoiddefense_RendererWrapper_get_1current_1music_1id(JNIEnv* env, jclass cls) { UNUSED(env); UNUSED(cls); return get_current_music_id(); }