接上篇博文:基于Platinum库的DMR实现(android)
文章讲述了如何使用Platinum库实现DMR
今天同样使用该库,来讲解一下DMS的实现
关于该库如何编译,请参考这篇博文: NDK下 将Platinum SDK 编译成so库 (android - upnp)
下面给出运行效果图:
界面很简单,就是一些开关和设备名以及设备运行状态的展现
下面看看代码片段:
JNI接口文件:
public class DMSJniInterface {
static {
System.loadLibrary("git-platinum");
}
public static native int startServer(byte[] rootDir,byte[] name ,byte[] uid);
public static native int stopServer();
public static native boolean enableLogPrint(boolean flag);
//
public static int startServer(String rootDir, String name ,String uid){
if (rootDir == null){
rootDir = "";
}
if (name == null){
name = "";
}
if (uid == null){
uid = "";
}
int ret = -1;
try {
ret = startServer(rootDir.getBytes("utf-8"), name.getBytes("utf-8"), uid.getBytes("utf-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return ret;
}
}
后台服务:
public class DMSService extends Service implements IBaseEngine{
private static final CommonLog log = LogFactory.createLog();
public static final String START_SERVER_ENGINE = "com.geniusgithub.start.dmsengine";
public static final String RESTART_SERVER_ENGINE = "com.geniusgithub.restart.dmsengine";
private DMSWorkThread mWorkThread;
private Handler mHandler;
private static final int START_ENGINE_MSG_ID = 0x0001;
private static final int RESTART_ENGINE_MSG_ID = 0x0002;
private static final int DELAY_TIME = 1000;
private MediaStoreCenter mMediaStoreCenter;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
initService();
log.e("MediaServerService onCreate");
}
@Override
public void onDestroy() {
unInitService();
log.e("MediaServerService onDestroy");
super.onDestroy();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent != null){
String actionString = intent.getAction();
if (actionString != null){
if (actionString.equalsIgnoreCase(START_SERVER_ENGINE)){
delayToSendStartMsg();
}else if (actionString.equalsIgnoreCase(RESTART_SERVER_ENGINE)){
delayToSendRestartMsg();
}
}
}
return super.onStartCommand(intent, flags, startId);
}
private void initService(){
mWorkThread = new DMSWorkThread(this);
mHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
switch(msg.what){
case START_ENGINE_MSG_ID:
startEngine();
break;
case RESTART_ENGINE_MSG_ID:
restartEngine();
break;
}
}
};
mMediaStoreCenter = MediaStoreCenter.getInstance();
mMediaStoreCenter.clearWebFolder();
mMediaStoreCenter.createWebFolder();
mMediaStoreCenter.doScanMedia();
}
private void unInitService(){
stopEngine();
removeStartMsg();
removeRestartMsg();
mMediaStoreCenter.clearAllData();