Next blog: dlna Development (Android) based on the cybergarage Library)
This article describes the DMP implementation using the cybergarage library.
Some kids shoes want to know How DMR works.
No Android code is displayed on the Internet.
Click it next and upload it to GitHub.
I am here to share with them
The UPnP framework used in this example is the platinum SDK.
Official website is http://www.plutinosoft.com/platinum
This library is a cross-platform C ++ library. With this library, you can easily build the dlna/UPnP Control Point (dlna/UPnP Control Point) and the dlna/UPnP Device (dlna/UPnP Device), including examples of UPnP AV Media Server, media render & Control Point
This database is stable and powerful, and is used by many well-known products. Its reputation is naturally favored by the landlord.
For details about how to compile this library, refer to this blog post: Compile the platinum SDK into the so Library Under ndk.
Run the following command:
JNI interface file:
public class PlatinumJniProxy { static { System.loadLibrary("git-platinum"); } public static native int startMediaRender(byte[] friendname ,byte[] uuid); public static native int stopMediaRender(); public static native boolean responseGenaEvent(int cmd, byte[] value ,byte[] data); public static native boolean enableLogPrint(boolean flag); public static int startMediaRender(String friendname ,String uuid){ if (friendname == null)friendname = ""; if (uuid == null)uuid = ""; int ret = -1; try { ret = startMediaRender(friendname.getBytes("utf-8"), uuid.getBytes("utf-8"));} catch (UnsupportedEncodingException e) {e.printStackTrace();} return ret; } public static boolean responseGenaEvent(int cmd, String value, String data){ if (value == null)value = ""; if (data == null)data = ""; boolean ret = false; try {ret = responseGenaEvent(cmd, value.getBytes("utf-8"), data.getBytes("utf-8"));} catch (UnsupportedEncodingException e) {e.printStackTrace();} return ret; } }
Reflection class:
public class PlatinumReflection {private static final CommonLog log = LogFactory.createLog();private static final int MEDIA_RENDER_CTL_MSG_BASE = 0x100;/*----------------------------------------------------------------*/public static final int MEDIA_RENDER_CTL_MSG_SET_AV_URL = (MEDIA_RENDER_CTL_MSG_BASE+0);public static final int MEDIA_RENDER_CTL_MSG_STOP = (MEDIA_RENDER_CTL_MSG_BASE+1);public static final int MEDIA_RENDER_CTL_MSG_PLAY = (MEDIA_RENDER_CTL_MSG_BASE+2);public static final int MEDIA_RENDER_CTL_MSG_PAUSE = (MEDIA_RENDER_CTL_MSG_BASE+3);public static final int MEDIA_RENDER_CTL_MSG_SEEK = (MEDIA_RENDER_CTL_MSG_BASE+4);public static final int MEDIA_RENDER_CTL_MSG_SETVOLUME = (MEDIA_RENDER_CTL_MSG_BASE+5);public static final int MEDIA_RENDER_CTL_MSG_SETMUTE = (MEDIA_RENDER_CTL_MSG_BASE+6);public static final int MEDIA_RENDER_CTL_MSG_SETPLAYMODE = (MEDIA_RENDER_CTL_MSG_BASE+7);public static final int MEDIA_RENDER_CTL_MSG_PRE = (MEDIA_RENDER_CTL_MSG_BASE+8);public static final int MEDIA_RENDER_CTL_MSG_NEXT = (MEDIA_RENDER_CTL_MSG_BASE+9);/*----------------------------------------------------------------*//*----------------------------------------------------------------*//* * * * */public static final int MEDIA_RENDER_TOCONTRPOINT_SET_MEDIA_DURATION = (MEDIA_RENDER_CTL_MSG_BASE+0);public static final int MEDIA_RENDER_TOCONTRPOINT_SET_MEDIA_POSITION = (MEDIA_RENDER_CTL_MSG_BASE+1);public static final int MEDIA_RENDER_TOCONTRPOINT_SET_MEDIA_PLAYINGSTATE = (MEDIA_RENDER_CTL_MSG_BASE+2);/*----------------------------------------------------------------*/public static final String RENDERER_TOCONTRPOINT_CMD_INTENT_NAME="com.geniusgithub.platinum.tocontrolpointer.cmd.intent";public static final String GET_RENDERER_TOCONTRPOINT_CMD="get_dlna_renderer_tocontrolpointer.cmd";public static final String GET_PARAM_MEDIA_DURATION="get_param_media_duration";public static final String GET_PARAM_MEDIA_POSITION="get_param_media_position";public static final String GET_PARAM_MEDIA_PLAYINGSTATE="get_param_media_playingstate";/*----------------------------------------------------------------*/ public static final String MEDIA_PLAYINGSTATE_STOP="STOPPED"; public static final String MEDIA_PLAYINGSTATE_PAUSE="PAUSED_PLAYBACK"; public static final String MEDIA_PLAYINGSTATE_PLAYING="PLAYING"; public static final String MEDIA_PLAYINGSTATE_TRANSTION="TRANSITIONING"; public static final String MEDIA_PLAYINGSTATE_NOMEDIA="NO_MEDIA_PRESENT"; /*----------------------------------------------------------------*/ public static final String MEDIA_SEEK_TIME_TYPE_REL_TIME="REL_TIME"; public static final String MEDIA_SEEK_TIME_TYPE_TRACK_NR="TRACK_NR"; public static interface ActionReflectionListener{public void onActionInvoke(int cmd,String value,String data);}private static ActionReflectionListener mListener;public static void onActionReflection(int cmd,String value,String data){if (mListener != null){mListener.onActionInvoke(cmd, value, data);}}public static void setActionInvokeListener(ActionReflectionListener listener){mListener = listener;}}
Worker thread dmrworkthread
public class DMRWorkThread extends Thread implements IBaseEngine{private static final CommonLog log = LogFactory.createLog();private static final int CHECK_INTERVAL = 30 * 1000; private Context mContext = null;private boolean mStartSuccess = false;private boolean mExitFlag = false;private String mFriendName = "";private String mUUID = "";private RenderApplication mApplication;public DMRWorkThread(Context context){mContext = context;mApplication = RenderApplication.getInstance();}public void setFlag(boolean flag){mStartSuccess = flag;}public void setParam(String friendName, String uuid){mFriendName = friendName;mUUID = uuid;mApplication.updateDevInfo(mFriendName, mUUID);}public void awakeThread(){synchronized (this) {notifyAll();}}public void exit(){mExitFlag = true;awakeThread();}@Overridepublic void run() {log.e("DMRWorkThread run...");while(true){if (mExitFlag){stopEngine();break;}refreshNotify();synchronized(this){try{wait(CHECK_INTERVAL);}catch(Exception e){e.printStackTrace();}}if (mExitFlag){stopEngine();break;}}log.e("DMRWorkThread over...");}public void refreshNotify(){if (!CommonUtil.checkNetworkState(mContext)){return ;}if (!mStartSuccess){stopEngine();try {Thread.sleep(200);} catch (InterruptedException e) {e.printStackTrace();}boolean ret = startEngine();if (ret){mStartSuccess = true;}}}@Overridepublic boolean startEngine() {if (mFriendName.length() == 0){return false;}int ret = PlatinumJniProxy.startMediaRender(mFriendName, mUUID);boolean result = (ret == 0 ? true : false);mApplication.setDevStatus(result);return result;}@Overridepublic boolean stopEngine() {PlatinumJniProxy.stopMediaRender();mApplication.setDevStatus(false);return true;}@Overridepublic boolean restartEngine() {setFlag(false);awakeThread();return true;}}
After the device is enabled with startmediarender, it can be detected by the outside world. After the control point sends the control information
The callback of an action is executed through the static onactionreflection method of the reflection class platinumreflection.
The Gena event is passed through the responsegenaevent of the platinumjniproxy class.
For details, go down the code.
GitHub download page: https://github.com/geniusgithub/MediaRender
Dlna development documentation link: http://download.csdn.net/detail/geniuseoe2012/4969961
More brilliant, please pay attention to my csdn blog --> http://blog.csdn.net/geniuseoe2012