summaryrefslogtreecommitdiff
path: root/NxWidgets
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-07-17 10:18:36 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-07-17 10:18:36 -0600
commit8fdf85adf18386c3c916290561c99ba8e688fa1c (patch)
treec9557f071717c2630a66a3ff8b0b5623f8a0e46f /NxWidgets
parentbca3ae582082e0582d3068c12abe2c51413305b8 (diff)
downloadnuttx-8fdf85adf18386c3c916290561c99ba8e688fa1c.tar.gz
nuttx-8fdf85adf18386c3c916290561c99ba8e688fa1c.tar.bz2
nuttx-8fdf85adf18386c3c916290561c99ba8e688fa1c.zip
NxWM::CMediaPlayer: Fix some state-related bugs introduced yesterday. Improved state-related button displayes. Now correctly catches and handles file selection events
Diffstat (limited to 'NxWidgets')
-rw-r--r--NxWidgets/nxwm/include/cmediaplayer.hxx6
-rw-r--r--NxWidgets/nxwm/src/cmediaplayer.cxx204
2 files changed, 136 insertions, 74 deletions
diff --git a/NxWidgets/nxwm/include/cmediaplayer.hxx b/NxWidgets/nxwm/include/cmediaplayer.hxx
index 455792db5..0584429a4 100644
--- a/NxWidgets/nxwm/include/cmediaplayer.hxx
+++ b/NxWidgets/nxwm/include/cmediaplayer.hxx
@@ -229,6 +229,12 @@ namespace NxWM
void setVolumeLevel(void);
/**
+ * Check if a new file has been selected (or de-selected) in the list box
+ */
+
+ inline void checkFileSelection(void);
+
+ /**
* Handle a widget action event. For this application, that means image
* pre-release events.
*
diff --git a/NxWidgets/nxwm/src/cmediaplayer.cxx b/NxWidgets/nxwm/src/cmediaplayer.cxx
index 757b0b96e..ffe0692d1 100644
--- a/NxWidgets/nxwm/src/cmediaplayer.cxx
+++ b/NxWidgets/nxwm/src/cmediaplayer.cxx
@@ -799,16 +799,13 @@ void CMediaPlayer::redrawWidgets(void)
m_play->redraw();
}
- // Rewind and play buttons are only shown if we are not STOPPED
+ // Rewind and play buttons
- if (m_state != MPLAYER_STOPPED)
- {
- m_rewind->enableDrawing();
- m_rewind->redraw();
+ m_rewind->enableDrawing();
+ m_rewind->redraw();
- m_fforward->enableDrawing();
- m_fforward->redraw();
- }
+ m_fforward->enableDrawing();
+ m_fforward->redraw();
m_volume->enableDrawing();
m_volume->redraw();
@@ -838,10 +835,18 @@ void CMediaPlayer::setMediaPlayerState(enum EMediaPlayerState state)
m_listbox->enable();
- // Play image enabled and ready to start playing
- // REVISIT: Really only available if there is a selected file in the list box
+ // Play image is visible, but enabled and ready to start playing only
+ // if a file is selected
+
+ if (m_fileIndex < 0)
+ {
+ m_play->disable();
+ }
+ else
+ {
+ m_play->enable();
+ }
- m_play->enable();
m_play->show();
// Pause image is disabled and hidden
@@ -1031,6 +1036,83 @@ void CMediaPlayer::setVolumeLevel(void)
}
/**
+ * Check if a new file has been selected (or de-selected) in the list box
+ */
+
+void CMediaPlayer::checkFileSelection(void)
+{
+ // Check for new file selections from the list box
+
+ int newFileIndex = m_listbox->getSelectedIndex();
+
+ // Check if anything is selected
+
+ if (newFileIndex < 0)
+ {
+ // No file is selected
+
+ m_fileIndex = -1;
+
+ // Nothing is selected.. If we are not stopped, then stop now
+
+ if (m_state != MPLAYER_STOPPED)
+ {
+ closeMediaFile();
+ setMediaPlayerState(MPLAYER_STOPPED);
+ }
+ }
+
+ // A media file is selected. Were stopped before?
+
+ else if (m_state == MPLAYER_STOPPED)
+ {
+ // Yes.. open the new media file and go to the PAUSE state
+
+ if (!openMediaFile(m_listbox->getSelectedOption()))
+ {
+ // Remain in the stopped state if we fail to open the file
+
+ m_fileIndex = -1;
+ gdbg("openMediaFile failed\m");
+ }
+ else
+ {
+ // And go to the PAUSED state (enabling the PLAY button)
+
+ m_fileIndex = newFileIndex;
+ setMediaPlayerState(MPLAYER_PAUSED);
+ }
+ }
+
+ // We already have a media file loaded. Is it the same file?
+
+ else if (m_fileIndex != newFileIndex)
+ {
+ // No.. It is a new file. Close that media file, load the newly
+ // selected file, and make sure that we are in the paused state
+ // (that should already be the case)
+
+ closeMediaFile();
+ if (!openMediaFile(m_listbox->getSelectedOption()))
+ {
+ // Go to the STOPPED state on a failure to open the media file
+ // The play button will be disable because m_fileIndex == -1.
+
+ gdbg("openMediaFile failed\m");
+ m_fileIndex = -1;
+ setMediaPlayerState(MPLAYER_STOPPED);
+ }
+ else
+ {
+ // And go to the PAUSED state (enabling the PLAY button)
+
+ m_fileIndex = newFileIndex;
+ setMediaPlayerState(MPLAYER_PAUSED);
+ }
+ }
+}
+
+/**
* Handle a widget action event. For this application, that means image
* pre-release events.
*
@@ -1113,90 +1195,62 @@ void CMediaPlayer::handleActionEvent(const NXWidgets::CWidgetEventArgs &e)
}
}
}
+}
- // Check for new file selections from the list box
-
- int newFileIndex = m_listbox->getSelectedIndex();
+/**
+ * Handle a widget release event. Only the play and pause image release
+ * are of interest.
+ */
- // Check if anything is selected
+void CMediaPlayer::handleReleaseEvent(const NXWidgets::CWidgetEventArgs &e)
+{
+ // Check if the Play image was released
- if (newFileIndex < 0)
+ if (m_pending == PENDING_PLAY_RELEASE && !m_play->isClicked())
{
- // Nothing is selected.. If we are not stopped, then stop now
+ // Yes.. Now perform the delayed state change
+ //
+ // If we were previously STOPPED or PAUSED, then enter the PLAYING
+ // state.
- if (m_state != MPLAYER_STOPPED)
+ if (m_state == MPLAYER_STOPPED || m_state == MPLAYER_PAUSED)
{
- closeMediaFile();
- setMediaPlayerState(MPLAYER_STOPPED);
+ setMediaPlayerState(MPLAYER_PLAYING);
}
- }
- // A media file is selected. Were stopped before?
+ // Ignore the event if we are already in the PLAYING state
- else if (m_state == MPLAYER_STOPPED)
- {
- // Yes.. open the new media file and go to the PAUSE state
-
- if (!openMediaFile(m_listbox->getSelectedOption()))
+ else if (m_state != MPLAYER_PLAYING)
{
- m_fileIndex = -1;
- gdbg("openMediaFile failed\m");
- }
- else
- {
- m_fileIndex = newFileIndex;
- setMediaPlayerState(MPLAYER_PAUSED);
+ // Otherwise, we must be fast forwarding or rewinding. In these
+ // cases, stop the action and return to the previous state
+
+ setMediaPlayerState(m_prevState);
}
}
- // We already have a media file loaded. Is it the same file?
+ // Check if the Pause image was released
- else if (m_fileIndex != newFileIndex)
+ else if (m_pending == PENDING_PAUSE_RELEASE && !m_pause->isClicked())
{
- // No.. It is a new file. Close that media file, load the newly
- // selected file, and make sure that we are in the paused state
- // (that should already be the case)
+ // Yes.. Now perform the delayed state change
+ //
+ // If we were previously PLAYING, then enter the PAUSED state.
- closeMediaFile();
- if (!openMediaFile(m_listbox->getSelectedOption()))
+ if (m_state == MPLAYER_PLAYING)
{
- gdbg("openMediaFile failed\m");
- m_fileIndex = -1;
- setMediaPlayerState(MPLAYER_STOPPED);
- }
- else
- {
- m_fileIndex = newFileIndex;
setMediaPlayerState(MPLAYER_PAUSED);
}
- }
-}
-/**
- * Handle a widget release event. Only the play and pause image release
- * are of interest.
- */
-
-void CMediaPlayer::handleReleaseEvent(const NXWidgets::CWidgetEventArgs &e)
-{
- // Check if the Play image was released
+ // Ignore the event if we are already in the PAUSED or STOPPED states
- if (m_pending == PENDING_PLAY_RELEASE && !m_play->isClicked())
- {
- // Now perform the delayed state change
-
- setMediaPlayerState(MPLAYER_PLAYING);
- m_pending = PENDING_NONE;
- }
-
- // Check if the Pause image was released
-
- else if (m_pending == PENDING_PAUSE_RELEASE && !m_pause->isClicked())
- {
- // Now perform the delayed state change
+ else if (m_state != MPLAYER_STOPPED && m_state != MPLAYER_PAUSED)
+ {
+ // Otherwise, we must be fast forwarding or rewinding. In these
+ // cases, stop the action and return to the previous state
- setMediaPlayerState(MPLAYER_PAUSED);
- m_pending = PENDING_NONE;
+ setMediaPlayerState(m_prevState);
+ }
}
}
@@ -1212,12 +1266,14 @@ void CMediaPlayer::handleReleaseOutsideEvent(const NXWidgets::CWidgetEventArgs &
}
/**
- * Handle changes in the volume level.
+ * Handle value changes. This will get events when there is a change in the
+ * volume level or a file is selected or deselected.
*/
void CMediaPlayer::handleValueChangeEvent(const NXWidgets::CWidgetEventArgs &e)
{
setVolumeLevel();
+ checkFileSelection();
}
/**