dmrJNI

HELLO, need to modify:

#include <jni.h>
#include "PltUPnP.h"
//#include "PltMediaRenderer.h"
#include "dmrJNI.h"
#include "HoperunMediaRenderer.h"

NPT_SET_LOCAL_LOGGER("platinum.media.renderer")

#define LISTEN_TYPE_NEXT	1
 #define LISTEN_TYPE_PAUSE	3
 #define LISTEN_TYPE_PLAY	5
 #define LISTEN_TYPE_PREVIOUS	7
 #define LISTEN_TYPE_SEEK	9
 #define LISTEN_TYPE_STOP	11
 #define LISTEN_TYPE_SETAVTRANSPORTURI	13
 #define LISTEN_TYPE_SETVOLUME	15
 #define LISTEN_TYPE_SETMUTE	17
static PLT_UPnP upnp;
static PLT_DeviceHostReference device;
static bool deviceAdded = false;

// 由于这个是全局存在,所以,同时这里限制了,一个apk里面,只能有一个render,否则就会引起混乱
static jobject player = NULL;
JavaVM*   gJavaVM;
JNIEnv*   gJniEnv;
jclass clazz;
jmethodID postEventMethodID;
//------------
extern "C" {
    JNIEXPORT int JNICALL Java_com_hoperun_renderer_PlayerDNRControl_deviceStart(JNIEnv *env, jobject obj);
    JNIEXPORT int JNICALL Java_com_hoperun_renderer_PlayerDNRControl_deviceStop(JNIEnv *env, jobject obj);
    //JNIEXPORT void JNICALL Java_com_hoperun_renderer_DMR_nativesetup(JNIEnv *env, jobject obj, jobject param);
   JNIEXPORT void JNICALL Java_com_hoperun_renderer_PlayerDNRControl_nativesetup(JNIEnv *env, jobject obj, jobject param);
};

// 其实这个函数就是为了保存this指针,留其他地方调用
JNIEXPORT  void JNICALL Java_com_hoperun_renderer_PlayerDNRControl_nativesetup(JNIEnv *env, jobject obj, jobject param)
{
	NPT_LogManager::GetDefault().Configure("plist:.level=INFO;.handlers=ConsoleHandler;.ConsoleHandler.colors=off;.ConsoleHandler.filter=42");
	NPT_LOG_INFO("baojinyu .-----nativesetup-----1");	
	player = param;
	//JavaVM*   javaVM;
	env->GetJavaVM(&gJavaVM);
	NPT_LOG_INFO("baojinyu .-----nativesetup-----2");		
    gJniEnv=env;
    clazz = gJniEnv->FindClass("com/hoperun/renderer/PlayerDNRControl");
    NPT_LOG_INFO("baojinyu .-----nativesetup-----3");	
    postEventMethodID = gJniEnv->GetStaticMethodID(clazz, "postEvent", "(Ljava/lang/Object;ILjava/lang/String)V");
    NPT_LOG_INFO("baojinyu .-----nativesetup-----4");	
}

// 1. 添加一个头文件,声明 void notify(int listenerType),并include在本文件头部
// 2. 这样其他函数include这个头文件,就可以调用notify这个函数,来向java调用函数
/**
 * listenerType:
 * OnNext---1
 * OnPause---3
 * OnPlay---5
 * OnPrevious---7
 * OnSeek------9
 * OnStop ------11
 * OnSetAVTransportURI----13
 * OnSetVolume------15
 * OnSetMute------17
 * */
void notify(int listenerType,const char* arg1,const char* arg2)
{	
	NPT_LOG_INFO("baojinyu .-----notify-1");
	if(player == NULL) 
	{
		NPT_LOG_INFO("baojinyu-----player == NULL!\n ");
		return;
	}
	
	//jclass clazz = gJniEnv->FindClass("com/hoperun/renderer/PlayerDNRControl");
	
	NPT_LOG_INFO("baojinyu .-----notify-2");
	
	
	//jmethodID postEventMethodID = gJniEnv->GetStaticMethodID(clazz, "postEvent", "(Ljava/lang/Object;ILjava/lang/String)V");
	
	if(postEventMethodID)
	{		
		//将uri转换后传给java		
		jstring jarg1 = gJniEnv->NewStringUTF(arg1);
		jstring jarg2 = gJniEnv->NewStringUTF(arg2);
		NPT_LOG_INFO("baojinyu .-----notify-3");
		gJniEnv->CallStaticVoidMethod(clazz, postEventMethodID,player,listenerType,jarg1,jarg2);
		NPT_LOG_INFO("baojinyu .-----notify-4");
	}
}

//dmc调用dmr的时候,调用notify

/**
 * 启动DMR设备
 * */
JNIEXPORT int JNICALL Java_com_hoperun_renderer_PlayerDNRControl_deviceStart(JNIEnv *env, jobject obj)
{
	// setup Neptune logging
    NPT_LogManager::GetDefault().Configure("plist:.level=INFO;.handlers=ConsoleHandler;.ConsoleHandler.colors=off;.ConsoleHandler.filter=42");
	NPT_LOG_INFO("baojinyu------------enter start()\n");
	/* for DLNA faster testing */
	PLT_Constants::GetInstance().SetDefaultDeviceLease(300.);
	
	device = new Hoperun_MediaRenderer("Renderer",
                                true,
                                "555666");
    
    upnp.AddDevice(device);
    NPT_LOG_INFO("baojinyu------------upnp.AddDevice success\n");
    
    NPT_CHECK_SEVERE(upnp.Start());
    NPT_LOG_INFO("baojinyu------------NPT_CHECK upnp.Start success\n");
    deviceAdded = true;
    
	return 0;	
}

/**
 * 停止DMR设备
 * 
 * */

JNIEXPORT int JNICALL Java_com_hoperun_renderer_PlayerDNRControl_deviceStop(JNIEnv *env, jobject obj)
{
	upnp.RemoveDevice(device);
	deviceAdded = false;
	NPT_LOG_INFO("baojinyu-------------------->render stop1.\n");
	upnp.Stop();	
	NPT_LOG_INFO("baojinyu-------------------->render stop2.\n");
	return 0;	
}


你可能感兴趣的:(java,null,include,logging,testing,Constants)