2010-12-10 18:41:09 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Thomas Martitz
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <jni.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "notification.h"
|
|
|
|
#include "appevents.h"
|
|
|
|
#include "metadata.h"
|
|
|
|
#include "misc.h"
|
|
|
|
|
|
|
|
extern JNIEnv *env_ptr;
|
|
|
|
extern jclass RockboxService_class;
|
|
|
|
extern jobject RockboxService_instance;
|
|
|
|
|
2011-01-29 20:47:32 +00:00
|
|
|
static jmethodID updateNotification, finishNotification;
|
2010-12-10 18:41:09 +00:00
|
|
|
static jobject NotificationManager_instance;
|
2011-01-24 17:10:56 +00:00
|
|
|
static jstring title, artist, album;
|
2010-12-10 18:41:09 +00:00
|
|
|
|
|
|
|
#define NZV(a) (a && a[0])
|
|
|
|
|
|
|
|
/*
|
|
|
|
* notify about track change, and show track info */
|
|
|
|
static void track_changed_callback(void *param)
|
|
|
|
{
|
|
|
|
struct mp3entry* id3 = (struct mp3entry*)param;
|
|
|
|
JNIEnv e = *env_ptr;
|
|
|
|
if (id3)
|
|
|
|
{
|
|
|
|
/* passing NULL to DeleteLocalRef() is OK */
|
2011-01-24 17:10:56 +00:00
|
|
|
e->DeleteLocalRef(env_ptr, title);
|
|
|
|
e->DeleteLocalRef(env_ptr, artist);
|
|
|
|
e->DeleteLocalRef(env_ptr, album);
|
2010-12-10 18:41:09 +00:00
|
|
|
|
|
|
|
char buf[200];
|
2011-01-24 17:10:56 +00:00
|
|
|
const char * ptitle = id3->title;
|
|
|
|
if (!ptitle)
|
2010-12-10 18:41:09 +00:00
|
|
|
{ /* pass the filename as title if id3 info isn't available */
|
2011-01-24 17:10:56 +00:00
|
|
|
ptitle =
|
2010-12-10 18:41:09 +00:00
|
|
|
strip_extension(buf, sizeof(buf), strrchr(id3->path,'/') + 1);
|
|
|
|
}
|
|
|
|
|
2011-01-24 17:10:56 +00:00
|
|
|
title = e->NewStringUTF(env_ptr, ptitle);
|
|
|
|
artist = e->NewStringUTF(env_ptr, id3->artist ?: "");
|
|
|
|
album = e->NewStringUTF(env_ptr, id3->album ?: "");
|
2010-12-10 18:41:09 +00:00
|
|
|
|
|
|
|
e->CallVoidMethod(env_ptr, NotificationManager_instance,
|
2011-01-24 17:10:56 +00:00
|
|
|
updateNotification, title, artist, album);
|
2010-12-10 18:41:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-29 20:47:32 +00:00
|
|
|
/*
|
|
|
|
* notify about track finishing */
|
|
|
|
static void track_finished_callback(void *param)
|
|
|
|
{
|
|
|
|
(void)param;
|
|
|
|
JNIEnv e = *env_ptr;
|
|
|
|
e->CallVoidMethod(env_ptr, NotificationManager_instance,
|
|
|
|
finishNotification);
|
|
|
|
}
|
|
|
|
|
2010-12-10 18:41:09 +00:00
|
|
|
void notification_init(void)
|
|
|
|
{
|
|
|
|
JNIEnv e = *env_ptr;
|
|
|
|
jfieldID nNM = e->GetFieldID(env_ptr, RockboxService_class,
|
|
|
|
"fg_runner", "Lorg/rockbox/Helper/RunForegroundManager;");
|
|
|
|
NotificationManager_instance = e->GetObjectField(env_ptr,
|
|
|
|
RockboxService_instance, nNM);
|
|
|
|
|
|
|
|
jclass class = e->GetObjectClass(env_ptr, NotificationManager_instance);
|
|
|
|
updateNotification = e->GetMethodID(env_ptr, class, "updateNotification",
|
|
|
|
"(Ljava/lang/String;"
|
|
|
|
"Ljava/lang/String;"
|
|
|
|
"Ljava/lang/String;)V");
|
2011-01-29 20:47:32 +00:00
|
|
|
finishNotification = e->GetMethodID(env_ptr, class, "finishNotification",
|
|
|
|
"()V");
|
2011-01-24 17:10:56 +00:00
|
|
|
|
2010-12-10 18:41:09 +00:00
|
|
|
add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, track_changed_callback);
|
2011-01-29 20:47:32 +00:00
|
|
|
add_event(PLAYBACK_EVENT_TRACK_FINISH, false, track_finished_callback);
|
2010-12-10 18:41:09 +00:00
|
|
|
}
|