summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorJerome Kuptz <jeromekuptz@gmail.com>2003-07-20 21:29:16 +0000
committerJerome Kuptz <jeromekuptz@gmail.com>2003-07-20 21:29:16 +0000
commitc7d42bbbd7641c8e9e06b28000c4c02c2ee36d21 (patch)
tree6a8ad9d5ef9642c5a5b7371ef8f2fc772df1c8d7 /apps
parentcb2caf7e0d66956151b0e484f261f2ea932305ab (diff)
downloadrockbox-c7d42bbbd7641c8e9e06b28000c4c02c2ee36d21.zip
rockbox-c7d42bbbd7641c8e9e06b28000c4c02c2ee36d21.tar.gz
rockbox-c7d42bbbd7641c8e9e06b28000c4c02c2ee36d21.tar.bz2
rockbox-c7d42bbbd7641c8e9e06b28000c4c02c2ee36d21.tar.xz
update to the api to allow fetching of currently playing id3 struct. Adding the favorites plugin.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3854 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/plugin.c2
-rw-r--r--apps/plugin.h6
-rw-r--r--apps/plugins/favorites.c51
3 files changed, 57 insertions, 2 deletions
diff --git a/apps/plugin.c b/apps/plugin.c
index ad3cbdc..08358aa 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -31,6 +31,7 @@
#include "plugin.h"
#include "lang.h"
#include "keyboard.h"
+#include "mpeg.h"
#ifdef HAVE_LCD_BITMAP
#include "widgets.h"
@@ -134,6 +135,7 @@ static struct plugin_api rockbox_api = {
splash,
qsort,
kbd_input,
+ mpeg_current_track,
};
int plugin_load(char* plugin, void* parameter)
diff --git a/apps/plugin.h b/apps/plugin.h
index dab3320..6926797 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -39,9 +39,10 @@
#include "font.h"
#include "system.h"
#include "lcd.h"
-
+#include "id3.h"
+#include "mpeg.h"
/* increase this every time the api struct changes */
-#define PLUGIN_API_VERSION 4
+#define PLUGIN_API_VERSION 5
/* plugin return codes */
enum plugin_status {
@@ -162,6 +163,7 @@ struct plugin_api {
void (*qsort)(void *base, size_t nmemb, size_t size,
int(*compar)(const void *, const void *));
int (*kbd_input)(char* buffer, int buflen);
+ struct mp3entry* (*mpeg_current_track)();
};
/* defined by the plugin loader (plugin.c) */
diff --git a/apps/plugins/favorites.c b/apps/plugins/favorites.c
new file mode 100644
index 0000000..5900164
--- /dev/null
+++ b/apps/plugins/favorites.c
@@ -0,0 +1,51 @@
+#include "plugin.h"
+#define FAVORITES_FILE "/favorites.m3u"
+
+static struct plugin_api* rb;
+
+enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
+{
+ struct mp3entry* id3;
+ char track_path[MAX_PATH+1];
+ int fd, seek, result, len;
+
+ /* this macro should be called as the first thing you do in the plugin.
+ it test that the api version and model the plugin was compiled for
+ matches the machine it is running on */
+ TEST_PLUGIN_API(api);
+
+ /* if you don't use the parameter, you can do like
+ this to avoid the compiler warning about it */
+ (void)parameter;
+
+ rb = api;
+
+ id3 = rb->mpeg_current_track();
+ if (!id3)
+ return PLUGIN_ERROR;
+
+ fd = rb->open(FAVORITES_FILE, O_WRONLY);
+
+ // creat the file if it does not return on open.
+ if (fd < 0)
+ fd = rb->creat(FAVORITES_FILE, 0);
+
+ if (fd > 0) {
+ rb->strcpy(track_path, id3->path);
+ len = rb->strlen(track_path);
+
+ // seek to the end of file
+ seek = rb->lseek(fd, 0, SEEK_END);
+ // append the current mp3 path
+ track_path[len] = '\n';
+ result = rb->write(fd, track_path, len + 1);
+ track_path[len] = '\0';
+ rb->close(fd);
+ }
+
+ rb->splash(HZ*2, 0, true, "Saved Favorite");
+
+ return PLUGIN_OK;
+}
+
+