From dc388b2bd44718d09d2f9e817c50702ad6ffdd55 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 27 Jul 2014 12:25:15 -0600 Subject: NxWM::CMediaPlayer: successive presses on fast forward or rewind button now increase the subsampling, wrapping back to 2X when the maximum of 16x is reached. --- NxWidgets/nxwm/include/cmediaplayer.hxx | 11 +++++-- NxWidgets/nxwm/src/cmediaplayer.cxx | 53 ++++++++++++++++++++++++--------- 2 files changed, 47 insertions(+), 17 deletions(-) (limited to 'NxWidgets/nxwm') diff --git a/NxWidgets/nxwm/include/cmediaplayer.hxx b/NxWidgets/nxwm/include/cmediaplayer.hxx index ea1133f98..fc71c0b25 100644 --- a/NxWidgets/nxwm/include/cmediaplayer.hxx +++ b/NxWidgets/nxwm/include/cmediaplayer.hxx @@ -2,7 +2,9 @@ * NxWidgets/nxwm/include/cmediaplayer.hxx * * Copyright (C) 2013 Ken Pettit. All rights reserved. + * Copyright (C) 2014 Gregory Nutt. All rights reserved. * Author: Ken Pettit + * Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -93,8 +95,8 @@ namespace NxWM * STAGED | STAGED | STOPPED | PLAYING | X | X | X | * PLAYING | X | X | X | PAUSED |FFORWARD2 | REWIND2 | * PAUSED | STAGED | STOPPED | PLAYING | X |FFORWARD1 | REWIND1 | - * FFORWARD1| X | X | PAUSED | X | PAUSED | REWIND1 | - * REWIND1 | X | X | PAUSED | X |FFORWARD1 | PAUSED | + * FFORWARD1| X | X | PAUSED | X |FFORWARD1 | REWIND1 | + * REWIND1 | X | X | PAUSED | X |FFORWARD1 | REWIND1 | * FFORWARD2| X | X | X | PLAYING | PLAYING | REWIND1 | * REWIND2 | X | X | X | PLAYING |FFORWARD1 | PLAYING | * ---------+----------+----------+----------+----------+----------+----------+ @@ -152,11 +154,14 @@ namespace NxWM enum EMediaPlayerState m_prevState; /**< Media player previous state */ enum EPendingRelease m_pending; /**< Pending image release event */ NXWidgets::CNxString m_filePath; /**< The full path to the selected file */ - unsigned int m_fileIndex; /**< Last selected text box selection */ + int m_fileIndex; /**< Last selected text box selection */ bool m_fileReady; /**< True: Ready to play */ #ifndef CONFIG_AUDIO_EXCLUDE_VOLUME uint8_t m_level; /**< Current volume level, range 0-100 */ #endif +#ifndef CONFIG_AUDIO_EXCLUDE_FFORWARD + uint8_t m_subSample; /**< Current FFFORWARD subsampling */ +#endif /** * Media player geometry. diff --git a/NxWidgets/nxwm/src/cmediaplayer.cxx b/NxWidgets/nxwm/src/cmediaplayer.cxx index cd76e5a9c..ad63e13cd 100644 --- a/NxWidgets/nxwm/src/cmediaplayer.cxx +++ b/NxWidgets/nxwm/src/cmediaplayer.cxx @@ -136,6 +136,9 @@ CMediaPlayer::CMediaPlayer(CTaskbar *taskbar, CApplicationWindow *window) m_fileIndex = -1; #ifndef CONFIG_AUDIO_EXCLUDE_VOLUME m_level = 0; +#endif +#ifndef CONFIG_AUDIO_EXCLUDE_FFORWARD + m_subSample = AUDIO_SUBSAMPLE_NONE; #endif m_fileReady = false; @@ -1504,13 +1507,22 @@ void CMediaPlayer::handleActionEvent(const NXWidgets::CWidgetEventArgs &e) if (m_state == MPLAYER_FREWIND) { - // Yes.. then revert to the previous play/pause state - // REVISIT: Or just increase rewind speed? + // Yes.. then just increase rewind rate (by specifying a + // higher level of sub-sampling) + + if (m_subSample >= AUDIO_SUBSAMPLE_MAX) + { + m_subSample = AUDIO_SUBSAMPLE_MIN; + } + else + { + m_subSample++; + } - int ret = nxplayer_cancel_motion(m_player, m_prevState == MPLAYER_PAUSED); + int ret = nxplayer_rewind(m_player, m_subSample); if (ret < 0) { - dbg("ERROR: nxplayer_cancel_motion failed: %d\n", ret); + dbg("ERROR: nxplayer_rewind failed: %d\n", ret); } else { @@ -1522,9 +1534,11 @@ void CMediaPlayer::handleActionEvent(const NXWidgets::CWidgetEventArgs &e) else if (m_state != MPLAYER_STOPPED && m_state != MPLAYER_STAGED) { - // Start rewinding + // Start rewinding at the minimum rate + + m_subSample = AUDIO_SUBSAMPLE_MIN; - int ret = nxplayer_rewind(m_player, SUBSAMPLE_4X); + int ret = nxplayer_rewind(m_player, m_subSample); if (ret < 0) { dbg("ERROR: nxplayer_rewind failed: %d\n", ret); @@ -1546,17 +1560,22 @@ void CMediaPlayer::handleActionEvent(const NXWidgets::CWidgetEventArgs &e) if (m_state == MPLAYER_FFORWARD) { - // Yes.. then revert to the previous play/pause state - // REVISIT: Or just increase fast forward speed? + // Yes.. then just increase fast forward rate (by specifying a + // level level of sub-sampling) - int ret = nxplayer_cancel_motion(m_player, m_prevState == MPLAYER_PAUSED); - if (ret < 0) + if (m_subSample >= AUDIO_SUBSAMPLE_MAX) { - dbg("ERROR: nxplayer_cancel_motion failed: %d\n", ret); + m_subSample = AUDIO_SUBSAMPLE_MIN; } else { - setMediaPlayerState(m_prevState); + m_subSample++; + } + + int ret = nxplayer_fforward(m_player, m_subSample); + if (ret < 0) + { + dbg("ERROR: nxplayer_fforward failed: %d\n", ret); } } @@ -1564,9 +1583,11 @@ void CMediaPlayer::handleActionEvent(const NXWidgets::CWidgetEventArgs &e) else if (m_state != MPLAYER_STOPPED && m_state != MPLAYER_STAGED) { - // Start fast forwarding + // Start fast forwarding at the minimum rate + + m_subSample = AUDIO_SUBSAMPLE_MIN; - int ret = nxplayer_fforward(m_player, SUBSAMPLE_4X); + int ret = nxplayer_fforward(m_player, m_subSample); if (ret < 0) { dbg("ERROR: nxplayer_fforward failed: %d\n", ret); @@ -1663,6 +1684,8 @@ void CMediaPlayer::handleReleaseEvent(const NXWidgets::CWidgetEventArgs &e) // In these states, stop the fast motion action and return to the // previous state + m_subSample = AUDIO_SUBSAMPLE_NONE; + int ret = nxplayer_cancel_motion(m_player, m_prevState == MPLAYER_PAUSED); if (ret < 0) { @@ -1714,6 +1737,8 @@ void CMediaPlayer::handleReleaseEvent(const NXWidgets::CWidgetEventArgs &e) // Otherwise, we must be fast forwarding or rewinding. In these // cases, stop the action and return to the previous state + m_subSample = AUDIO_SUBSAMPLE_NONE; + int ret = nxplayer_cancel_motion(m_player, m_prevState == MPLAYER_PAUSED); if (ret < 0) { -- cgit v1.2.3