Commented the functions of the API and corrected a last issue (I hope) with an integer overflow causing some sync issues. Music player should be perfect now !
This commit is contained in:
parent
1a425cce58
commit
d1f1481f13
@ -7,7 +7,7 @@
|
||||
static void _set_UI_no_ble_connection(MusicPlayerScreen_t * const musicPlayerScreen, bool connected);
|
||||
static void _update_playing_track_visuals(MusicPlayerScreen_t * const musicPlayerScreen);
|
||||
static void _update_playing_track_ref_time(MusicPlayerScreen_t * const musicPlayerScreen);
|
||||
static uint16_t _time_difference_in_ms(uint32_t referenceTimeMs, uint32_t currentTimeMs);
|
||||
static uint32_t _time_difference_in_ms(uint32_t referenceTimeMs, uint32_t currentTimeMs);
|
||||
|
||||
static void gesture_event_cb(lv_event_t *e)
|
||||
{
|
||||
@ -219,6 +219,9 @@ void music_player_screen_set_music_position(MusicPlayerScreen_t * const musicPla
|
||||
positionInSeconds = positionInSeconds > musicPlayerScreen->currentMusicDuration ? musicPlayerScreen->currentMusicDuration : positionInSeconds;
|
||||
musicPlayerScreen->currentMusicPosition = positionInSeconds * 1000;
|
||||
|
||||
//Don't forget to reset the time reference
|
||||
if(musicPlayerScreen->musicPlayerTimeRefmsCb)musicPlayerScreen->playerStartTimeRef = musicPlayerScreen->musicPlayerTimeRefmsCb();
|
||||
|
||||
//Let's update the current music position visually
|
||||
if(music_player_screen_is_in_use(musicPlayerScreen))
|
||||
{
|
||||
@ -513,14 +516,14 @@ static void _update_playing_track_ref_time(MusicPlayerScreen_t * const musicPlay
|
||||
{
|
||||
//Let's compute the time that has passed and update the current song position
|
||||
uint32_t currentTimeMs = musicPlayerScreen->musicPlayerTimeRefmsCb ? musicPlayerScreen->musicPlayerTimeRefmsCb() : 0;
|
||||
uint16_t timeDifferenceMs = _time_difference_in_ms(musicPlayerScreen->playerStartTimeRef, currentTimeMs);
|
||||
uint32_t timeDifferenceMs = _time_difference_in_ms(musicPlayerScreen->playerStartTimeRef, currentTimeMs);
|
||||
musicPlayerScreen->playerStartTimeRef = currentTimeMs;
|
||||
|
||||
musicPlayerScreen->currentMusicPosition = musicPlayerScreen->currentMusicPosition + timeDifferenceMs > musicPlayerScreen->currentMusicDuration * 1000 ?
|
||||
musicPlayerScreen->currentMusicDuration * 1000 : musicPlayerScreen->currentMusicPosition + timeDifferenceMs;
|
||||
}
|
||||
|
||||
static uint16_t _time_difference_in_ms(uint32_t referenceTimeMs, uint32_t currentTimeMs)
|
||||
static uint32_t _time_difference_in_ms(uint32_t referenceTimeMs, uint32_t currentTimeMs)
|
||||
{
|
||||
return currentTimeMs - referenceTimeMs;
|
||||
}
|
||||
|
@ -68,33 +68,101 @@ typedef struct MusicPlayerScreen
|
||||
*/
|
||||
void music_player_screen_init(MusicPlayerScreen_t * const musicPlayerScreen);
|
||||
|
||||
/**
|
||||
* @brief Registers a callback function which will be called every time an action (button pressed) is performed with the type of action given as the parameter.
|
||||
* This callback function can be used to forward the action to an other sub system like the BLE layer for example.
|
||||
*
|
||||
* @param musicPlayerScreen a pointer to the music player screen's context structure.
|
||||
* @param musicPlaybackCtrlCb a pointer to a function having the following signature : void(MusicPlaybackCtrlAction_e).
|
||||
* The action passed to the callback function can be of value :
|
||||
* - MUSIC_CONTROL_PLAY
|
||||
* - MUSIC_CONTROL_PAUSE
|
||||
* - MUSIC_CONTROL_PLAYPAUSE
|
||||
* - MUSIC_CONTROL_NEXT
|
||||
* - MUSIC_CONTROL_PREVIOUS
|
||||
* - MUSIC_CONTROL_VOLUMEUP
|
||||
* - MUSIC_CONTROL_VOLUMEDOWN
|
||||
* - MUSIC_CONTROL_FORWARD
|
||||
* - MUSIC_CONTROL_REWIND
|
||||
*/
|
||||
void music_player_screen_register_music_playback_control_cb(MusicPlayerScreen_t * const musicPlayerScreen, MusicPlaybackCtrlCb_t musicPlaybackCtrlCb);
|
||||
|
||||
/**
|
||||
* @brief Registers a callback function used by the music player to keep track of the system's time.
|
||||
* This time is internaly used as a reference to stay in sync with the playing track's playtime.
|
||||
* The function must return the system time in millisecond.
|
||||
*
|
||||
* @param musicPlayerScreen a pointer to the music player screen's context structure.
|
||||
* @param musicPlayerTimeRefmsCb a pointer to a function having the following signature : uint32_t(void).
|
||||
*/
|
||||
void music_player_screen_register_music_player_time_ref_ms_cb(MusicPlayerScreen_t * const musicPlayerScreen, MusicPlayerTimeRefmsCb_t musicPlayerTimeRefmsCb);
|
||||
|
||||
/**
|
||||
* @brief Tells the music player whether the watch is connected to a smartphone through a BLE connection or not.
|
||||
* It, for example, enables the music player to grey the music controls (buttons) out if there is no established BLE connection.
|
||||
*
|
||||
* @param musicPlayerScreen a pointer to the music player screen's context structure.
|
||||
* @param connected true if there is an active BLE connection, false otherwise.
|
||||
*/
|
||||
void music_player_screen_notify_BLE_connection_state(MusicPlayerScreen_t * const musicPlayerScreen, bool connected);
|
||||
|
||||
/**
|
||||
* @brief Displays the current song's title and artist on the music player UI.
|
||||
* If the information is not available, NULL can be passed as the value.
|
||||
* The string is internally copied, so it can be freed after the function was called.
|
||||
*
|
||||
* @param musicPlayerScreen a pointer to the music player screen's context structure.
|
||||
* @param title the title of the song
|
||||
* @param artist the artists
|
||||
*/
|
||||
void music_player_screen_set_playing_music_title_and_artist(MusicPlayerScreen_t * const musicPlayerScreen, const char *title, const char *artist);
|
||||
|
||||
/**
|
||||
* @brief Sets the song's duration in seconds to be displayed on the UI.
|
||||
*
|
||||
* @param musicPlayerScreen a pointer to the music player screen's context structure.
|
||||
* @param durationInSeconds the song's duration in seconds.
|
||||
*/
|
||||
void music_player_screen_set_music_duration(MusicPlayerScreen_t * const musicPlayerScreen, uint16_t durationInSeconds);
|
||||
|
||||
/**
|
||||
* @brief Sets the song's current playtime in seconds to be displayed on the UI.
|
||||
*
|
||||
* @param musicPlayerScreen a pointer to the music player screen's context structure.
|
||||
* @param positionInSeconds the song's playtime in seconds.
|
||||
*/
|
||||
void music_player_screen_set_music_position(MusicPlayerScreen_t * const musicPlayerScreen, uint16_t positionInSeconds);
|
||||
|
||||
/**
|
||||
* @brief Changes the current playing state of the song.
|
||||
* This function should be used to keep the music player in sync with external events (ie : paused is pressed on the smartphone).
|
||||
*
|
||||
* @param musicPlayerScreen a pointer to the music player screen's context structure.
|
||||
* @param playingState the new playing state to apply.
|
||||
* Only two music states are relevant : MUSIC_CONTROL_PAUSE and MUSIC_CONTROL_PLAY.
|
||||
*/
|
||||
void music_player_screen_set_music_playing_state(MusicPlayerScreen_t * const musicPlayerScreen, MusicPlaybackCtrlAction_e playingState);
|
||||
|
||||
/**
|
||||
* @brief Returns true if the music player screen is currently being displayed.
|
||||
*
|
||||
* @param musicPlayerScreen a pointer to the music player screen's context structure.
|
||||
* @return true if the music player screen is being used
|
||||
* @return false if the music player screen is not being used/currently displayed
|
||||
*/
|
||||
bool music_player_screen_is_in_use(MusicPlayerScreen_t * const musicPlayerScreen);
|
||||
|
||||
/**
|
||||
* @brief Graphically builds the music player screen.
|
||||
*
|
||||
* @param musicPlayerScreen a pointer to the music player screen's context structure to initialize.
|
||||
* @param musicPlayerScreen a pointer to the music player screen's context structure.
|
||||
*/
|
||||
void music_player_screen_create(MusicPlayerScreen_t * const musicPlayerScreen);
|
||||
|
||||
/**
|
||||
* @brief Frees all resources used by the MusicPlayerScreen object.
|
||||
*
|
||||
* @param musicPlayerScreen a pointer to the music player screen's context structure to initialize.
|
||||
* @param musicPlayerScreen a pointer to the music player screen's context structure.
|
||||
*/
|
||||
void music_player_screen_destroy(MusicPlayerScreen_t * const musicPlayerScreen);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user