summaryrefslogtreecommitdiff
path: root/NxWidgets
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-07-23 14:47:38 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-07-23 14:47:38 -0600
commit64b145bdb1166ea0f5eeea987550dc4c98d65bd5 (patch)
tree503e7e8b4bd588291fad881b81141ceba4aa17d6 /NxWidgets
parent979db409ef890e94e7f9637f3c8410e6eaf25b65 (diff)
downloadnuttx-64b145bdb1166ea0f5eeea987550dc4c98d65bd5.tar.gz
nuttx-64b145bdb1166ea0f5eeea987550dc4c98d65bd5.tar.bz2
nuttx-64b145bdb1166ea0f5eeea987550dc4c98d65bd5.zip
NxWM::CMediaPlayer: Add logic to read files from the media mountpoint, filter them by extension, and display the file names in the listbox
Diffstat (limited to 'NxWidgets')
-rw-r--r--NxWidgets/nxwm/src/cmediaplayer.cxx99
1 files changed, 80 insertions, 19 deletions
diff --git a/NxWidgets/nxwm/src/cmediaplayer.cxx b/NxWidgets/nxwm/src/cmediaplayer.cxx
index 14ca32eed..c3df41c8c 100644
--- a/NxWidgets/nxwm/src/cmediaplayer.cxx
+++ b/NxWidgets/nxwm/src/cmediaplayer.cxx
@@ -41,6 +41,8 @@
#include <nuttx/config.h>
#include <cstdio>
+#include <cstring>
+#include <dirent.h>
#include <debug.h>
#include "cwidgetcontrol.hxx"
@@ -396,27 +398,86 @@ inline bool CMediaPlayer::showMediaFiles(const char *mediaPath)
m_listbox->removeAllOptions();
-#if 0
// Open the media path directory
+
+ FAR DIR *dirp = opendir(CONFIG_NXWM_MEDIAPLAYER_MEDIAPATH);
+ if (!dirp)
+ {
+ m_listbox->addOption("Media volume is not mounted", 0,
+ MKRGB(192, 0, 0),
+ CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR,
+ MKRGB(255, 0, 0),
+ CONFIG_NXWM_DEFAULT_SELECTEDBACKGROUNDCOLOR);
+ return false;
+ }
+
// Read each directory entry
- // Add the directory entry to the list box
- // Close the directory
-#else
-# warning "Missing Logic"
-
- // Just add a couple of dummy files for testing
-
- m_listbox->addOption("File 1", 0,
- CONFIG_NXWIDGETS_DEFAULT_ENABLEDTEXTCOLOR,
- CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR,
- CONFIG_NXWIDGETS_DEFAULT_SELECTEDTEXTCOLOR,
- CONFIG_NXWM_DEFAULT_SELECTEDBACKGROUNDCOLOR);
- m_listbox->addOption("File 2", 1,
- CONFIG_NXWIDGETS_DEFAULT_ENABLEDTEXTCOLOR,
- CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR,
- CONFIG_NXWIDGETS_DEFAULT_SELECTEDTEXTCOLOR,
- CONFIG_NXWM_DEFAULT_SELECTEDBACKGROUNDCOLOR);
+
+ FAR struct dirent *direntry;
+ int index;
+
+ for (direntry = readdir(dirp), index = 0;
+ direntry;
+ direntry = readdir(dirp))
+ {
+ // TODO: Recursively examine files in all sub-directories
+ // Ignore directory entries beginning with '.'
+
+ if (direntry->d_name[0] == '.')
+ {
+ continue;
+ }
+
+#if defined(CONFIG_NXWM_MEDIAPLAYER_FILTER)
+ // Filter files by extension
+
+ FAR const char *extension = std::strchr(direntry->d_name, '.');
+ if (!extension || (true
+#if defined(CONFIG_NXWM_MEDIAPLAYER_FILTER_AC3
+ && std::strcmp(extension, ".ac3") != 0
+#endif
+#if defined(CONFIG_NXWM_MEDIAPLAYER_FILTER_DTS
+ && std::strcmp(extension, ".dts") != 0
+#endif
+#if defined(CONFIG_NXWM_MEDIAPLAYER_FILTER_WAV
+ && std::strcmp(extension, ".wav") != 0
#endif
+#if defined(CONFIG_NXWM_MEDIAPLAYER_FILTER_PCM
+ && std::strcmp(extension, ".pcm") != 0
+#endif
+#if defined(CONFIG_NXWM_MEDIAPLAYER_FILTER_MP3
+ && std::strcmp(extension, ".mp3") != 0
+#endif
+#if defined(CONFIG_NXWM_MEDIAPLAYER_FILTER_MIDI
+ && sstd::trcmp(extension, ".mid") != 0
+#endif
+#if defined(CONFIG_NXWM_MEDIAPLAYER_FILTER_WMA
+ && std::strcmp(extension, ".wma") != 0
+#endif
+#if defined(CONFIG_NXWM_MEDIAPLAYER_FILTER_OGGVORBIS
+ && std::strcmp(extension, ".ogg") != 0
+#endif
+ ))
+ {
+ // File does not match any configured extension
+
+ continue;
+ }
+#endif
+
+ // Add the directory entry to the list box
+
+ m_listbox->addOption(direntry->d_name, index,
+ CONFIG_NXWIDGETS_DEFAULT_ENABLEDTEXTCOLOR,
+ CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR,
+ CONFIG_NXWIDGETS_DEFAULT_SELECTEDTEXTCOLOR,
+ CONFIG_NXWM_DEFAULT_SELECTEDBACKGROUNDCOLOR);
+ index++;
+ }
+
+ // Close the directory
+
+ (void)closedir(dirp);
// Sort the file names in alphabetical order
@@ -526,7 +587,7 @@ bool CMediaPlayer::createPlayer(void)
// Show the media files that are available for playing
- showMediaFiles(CONFIG_NXWM_MEDIAPLAYER_MEDIAPATH);
+ (void)showMediaFiles(CONFIG_NXWM_MEDIAPLAYER_MEDIAPATH);
// Control image widths.
// Image widths will depend on if the images will be bordered or not