基於Platinum庫的DMS實現(android)

轉載地址:http://blog.csdn.net/lancees/article/details/9865411

下面給出運行效果圖:


界面很簡單,就是一些開關和設備名以及設備運行狀態的展現


下面看看代碼片段:

JNI接口文件:

  1. public class DMSJniInterface {  
  2.   
  3.     static {  
  4.         System.loadLibrary("git-platinum");  
  5.     }  
  6.    
  7.     public static native int startServer(byte[] rootDir,byte[] name ,byte[] uid);  
  8.     public static native int stopServer();    
  9.       
  10.       
  11.       
  12.     public static native boolean enableLogPrint(boolean flag);  
  13.        
  14.     //////////////////////////////////////////////////////////////////////////////////////////             
  15.     public static  int startServer(String rootDir, String name ,String uid){  
  16.         if (rootDir == null){  
  17.             rootDir = "";  
  18.         }  
  19.         if (name == null){  
  20.             name = "";  
  21.         }  
  22.         if (uid == null){  
  23.             uid = "";  
  24.         }  
  25.         int ret = -1;  
  26.         try {  
  27.             ret = startServer(rootDir.getBytes("utf-8"), name.getBytes("utf-8"), uid.getBytes("utf-8"));  
  28.         } catch (UnsupportedEncodingException e) {  
  29.             e.printStackTrace();  
  30.         }  
  31.         return ret;  
  32.     }  
  33.       
  34. }  


後臺服務:

  1. public class DMSService extends Service implements IBaseEngine{  
  2.   
  3.     private static final CommonLog log = LogFactory.createLog();  
  4.       
  5.     public static final String START_SERVER_ENGINE = "com.geniusgithub.start.dmsengine";  
  6.     public static final String RESTART_SERVER_ENGINE = "com.geniusgithub.restart.dmsengine";  
  7.   
  8.     private DMSWorkThread mWorkThread;  
  9.   
  10.     private Handler mHandler;  
  11.     private static final int START_ENGINE_MSG_ID = 0x0001;  
  12.     private static final int RESTART_ENGINE_MSG_ID = 0x0002;  
  13.       
  14.     private static final int DELAY_TIME = 1000;  
  15.       
  16.     private MediaStoreCenter mMediaStoreCenter;  
  17.       
  18.     @Override  
  19.     public IBinder onBind(Intent intent) {  
  20.         return null;  
  21.     }  
  22.   
  23.     @Override  
  24.     public void onCreate() {  
  25.         super.onCreate();         
  26.         initService();    
  27.         log.e("MediaServerService onCreate");  
  28.     }  
  29.   
  30.     @Override  
  31.     public void onDestroy() {  
  32.         unInitService();      
  33.         log.e("MediaServerService onDestroy");  
  34.         super.onDestroy();  
  35.       
  36.     }  
  37.   
  38.     @Override  
  39.     public int onStartCommand(Intent intent, int flags, int startId) {  
  40.           
  41.         if (intent != null){  
  42.             String actionString = intent.getAction();  
  43.             if (actionString != null){        
  44.                 if (actionString.equalsIgnoreCase(START_SERVER_ENGINE)){  
  45.                     delayToSendStartMsg();  
  46.                 }else if (actionString.equalsIgnoreCase(RESTART_SERVER_ENGINE)){  
  47.                     delayToSendRestartMsg();  
  48.                 }  
  49.             }  
  50.         }     
  51.       
  52.         return super.onStartCommand(intent, flags, startId);  
  53.           
  54.     }  
  55.       
  56.       
  57.     private void initService(){  
  58.   
  59.         mWorkThread = new DMSWorkThread(this);  
  60.           
  61.         mHandler = new Handler(){  
  62.             @Override  
  63.             public void handleMessage(Message msg) {  
  64.                 switch(msg.what){  
  65.                 case START_ENGINE_MSG_ID:  
  66.                     startEngine();  
  67.                     break;  
  68.                 case RESTART_ENGINE_MSG_ID:  
  69.                     restartEngine();  
  70.                     break;  
  71.                 }  
  72.             }  
  73.               
  74.         };  
  75.           
  76.         mMediaStoreCenter = MediaStoreCenter.getInstance();  
  77.         mMediaStoreCenter.clearWebFolder();  
  78.         mMediaStoreCenter.createWebFolder();  
  79.         mMediaStoreCenter.doScanMedia();  
  80.     }  
  81.   
  82.       
  83.     private void unInitService(){  
  84.         stopEngine();  
  85.         removeStartMsg();  
  86.         removeRestartMsg();  
  87.         mMediaStoreCenter.clearAllData();  
  88.     }  
  89.   
  90.     private void delayToSendStartMsg(){  
  91.         removeStartMsg();  
  92.         mHandler.sendEmptyMessageDelayed(START_ENGINE_MSG_ID, DELAY_TIME);  
  93.     }  
  94.       
  95.     private void delayToSendRestartMsg(){  
  96.         removeStartMsg();  
  97.         removeRestartMsg();  
  98.         mHandler.sendEmptyMessageDelayed(RESTART_ENGINE_MSG_ID, DELAY_TIME);  
  99.     }  
  100.       
  101.     private void removeStartMsg(){  
  102.         mHandler.removeMessages(START_ENGINE_MSG_ID);  
  103.     }  
  104.       
  105.     private void removeRestartMsg(){  
  106.         mHandler.removeMessages(RESTART_ENGINE_MSG_ID);   
  107.     }  
  108.       
  109.       
  110.     @Override  
  111.     public boolean startEngine() {  
  112.         awakeWorkThread();  
  113.         return true;  
  114.     }  
  115.   
  116.     @Override  
  117.     public boolean stopEngine() {  
  118.         mWorkThread.setParam("""""");  
  119.         exitWorkThread();  
  120.         return true;  
  121.     }  
  122.   
  123.     @Override  
  124.     public boolean restartEngine() {  
  125.         String friendName = DlnaUtils.getDevName(this);  
  126.         String uuid = DlnaUtils.creat12BitUUID(this);  
  127.         mWorkThread.setParam(mMediaStoreCenter.getRootDir(), friendName, uuid);  
  128.         if (mWorkThread.isAlive()){  
  129.             mWorkThread.restartEngine();  
  130.         }else{  
  131.             mWorkThread.start();  
  132.         }  
  133.         return true;  
  134.     }  
  135.   
  136.     private void awakeWorkThread(){  
  137.         String friendName = DlnaUtils.getDevName(this);  
  138.         String uuid = DlnaUtils.creat12BitUUID(this);  
  139.         mWorkThread.setParam(mMediaStoreCenter.getRootDir(), friendName, uuid);  
  140.           
  141.           
  142.         if (mWorkThread.isAlive()){  
  143.             mWorkThread.awakeThread();  
  144.         }else{  
  145.             mWorkThread.start();  
  146.         }  
  147.     }  
  148.       
  149.     private void exitWorkThread(){  
  150.         if (mWorkThread != null && mWorkThread.isAlive()){  
  151.             mWorkThread.exit();  
  152.             long time1 = System.currentTimeMillis();  
  153.             while(mWorkThread.isAlive()){  
  154.                 try {  
  155.                     Thread.sleep(100);  
  156.                 } catch (InterruptedException e) {  
  157.                     e.printStackTrace();  
  158.                 }  
  159.             }  
  160.             long time2 = System.currentTimeMillis();  
  161.             log.e("exitWorkThread cost time:" + (time2 - time1));  
  162.             mWorkThread = null;  
  163.         }  
  164.     }  
  165.   
  166.   
  167. }  

工作線程:

  1. public class DMSWorkThread extends Thread implements IBaseEngine{  
  2.   
  3.   
  4.     private static final CommonLog log = LogFactory.createLog();  
  5.       
  6.     private static final int CHECK_INTERVAL = 30 * 1000;   
  7.       
  8.     private Context mContext = null;  
  9.     private boolean mStartSuccess = false;  
  10.     private boolean mExitFlag = false;  
  11.       
  12.     private String mRootdir = "";  
  13.     private String mFriendName = "";  
  14.     private String mUUID = "";    
  15.     private ServerApplication mApplication;  
  16.       
  17.     public DMSWorkThread(Context context){  
  18.         mContext = context;  
  19.         mApplication = ServerApplication.getInstance();  
  20.     }  
  21.       
  22.     public void  setFlag(boolean flag){  
  23.         mStartSuccess = flag;  
  24.     }  
  25.       
  26.     public void setParam(String rootDir, String friendName, String uuid){  
  27.         mRootdir = rootDir;  
  28.         mFriendName = friendName;  
  29.         mUUID = uuid;  
  30.         mApplication.updateDevInfo(mRootdir, mFriendName, mUUID);  
  31.     }  
  32.       
  33.     public void awakeThread(){  
  34.         synchronized (this) {  
  35.             notifyAll();  
  36.         }  
  37.     }  
  38.       
  39.     public void exit(){  
  40.         mExitFlag = true;  
  41.         awakeThread();  
  42.     }  
  43.   
  44.     @Override  
  45.     public void run() {  
  46.   
  47.         log.e("DMSWorkThread run...");  
  48.           
  49.         while(true)  
  50.         {  
  51.             if (mExitFlag){  
  52.                 stopEngine();  
  53.                 break;  
  54.             }  
  55.             refreshNotify();  
  56.             synchronized(this)  
  57.             {                 
  58.                 try  
  59.                 {  
  60.                     wait(CHECK_INTERVAL);  
  61.                 }  
  62.                 catch(Exception e)  
  63.                 {  
  64.                     e.printStackTrace();  
  65.                 }                                 
  66.             }  
  67.             if (mExitFlag){  
  68.                 stopEngine();  
  69.                 break;  
  70.             }  
  71.         }  
  72.           
  73.         log.e("DMSWorkThread over...");  
  74.           
  75.     }  
  76.       
  77.     public void refreshNotify(){  
  78.         if (!CommonUtil.checkNetworkState(mContext)){  
  79.             return ;  
  80.         }  
  81.           
  82.         if (!mStartSuccess){  
  83.             stopEngine();  
  84.             try {  
  85.                 Thread.sleep(200);  
  86.             } catch (InterruptedException e) {  
  87.                 e.printStackTrace();  
  88.             }  
  89.             boolean ret = startEngine();  
  90.             if (ret){  
  91.                 mStartSuccess = true;  
  92.             }  
  93.         }  
  94.   
  95.     }  
  96.       
  97.     @Override  
  98.     public boolean startEngine() {  
  99.         if (mFriendName.length() == 0){  
  100.             return false;  
  101.         }  
  102.   
  103.         int ret = DMSJniInterface.startServer(mRootdir, mFriendName, mUUID);  
  104.           
  105.         boolean result = (ret == 0 ? true : false);  
  106.         mApplication.setDevStatus(result);  
  107.         return result;  
  108.     }  
  109.   
  110.     @Override  
  111.     public boolean stopEngine() {  
  112.         DMSJniInterface.stopServer();  
  113.         mApplication.setDevStatus(false);  
  114.         return true;  
  115.     }  
  116.   
  117.     @Override  
  118.     public boolean restartEngine() {  
  119.         setFlag(false);  
  120.         awakeThread();  
  121.         return true;  
  122.     }  
  123.   
  124. }  


多媒體遍歷:

  1. public class MediaScannerCenter {  
  2.   
  3.     private static final CommonLog log = LogFactory.createLog();  
  4.   
  5.     public static final int AUDIO_TYPE = 0;  
  6.     public static final int VIDEO_TYPE = 1;  
  7.     public static final int IMAGE_TYPE = 2;  
  8.   
  9.       
  10.       
  11.     String AUDIO_PATH = MediaStore.Audio.AudioColumns.DATA;  
  12.     String AUDIO_DISPLAYHNAME = MediaStore.Audio.AudioColumns.DISPLAY_NAME;  
  13.     String AUDIO_COLUMN_STRS[] = {AUDIO_PATH, AUDIO_DISPLAYHNAME};  
  14.       
  15.     String VIDEO_PATH = MediaStore.Video.VideoColumns.DATA;  
  16.     String VIDEO_DISPLAYHNAME  = MediaStore.Video.VideoColumns.DISPLAY_NAME;  
  17.     String VIDEO_COLUMN_STRS[] = {VIDEO_PATH, VIDEO_DISPLAYHNAME};  
  18.       
  19.     String IMAGE_PATH = MediaStore.Images.ImageColumns.DATA;  
  20.     String IMAGE_DISPLAYHNAME  = MediaStore.Images.ImageColumns.DISPLAY_NAME;  
  21.     String IMAGE_COLUMN_STRS[] = {IMAGE_PATH, IMAGE_DISPLAYHNAME};  
  22.       
  23.       
  24.     private static  MediaScannerCenter mInstance;  
  25.     private Context mContext;  
  26.       
  27.     private ScanMediaThread mediaThread;  
  28.       
  29.     private MediaScannerCenter(Context context) {  
  30.         mContext = context;  
  31.           
  32.         initData();  
  33.     }  
  34.   
  35.     public static synchronized MediaScannerCenter getInstance() {  
  36.         if (mInstance == null){  
  37.             mInstance  = new MediaScannerCenter(ServerApplication.getInstance());  
  38.         }  
  39.         return mInstance;  
  40.     }  
  41.   
  42.     private void initData(){  
  43.   
  44.   
  45.     }  
  46.       
  47.       
  48.     public synchronized boolean startScanThread(IMediaScanListener listener){  
  49.         if (mediaThread == null || !mediaThread.isAlive()){  
  50.             mediaThread = new ScanMediaThread(listener);  
  51.             mediaThread.start();  
  52.         }  
  53.           
  54.         return true;  
  55.     }  
  56.       
  57.     public synchronized void stopScanThread(){  
  58.         if (mediaThread != null){  
  59.             if (mediaThread.isAlive()){  
  60.                 mediaThread.exit();  
  61.             }  
  62.             mediaThread = null;  
  63.         }  
  64.     }  
  65.       
  66.     public synchronized boolean isThreadOver(){  
  67.         if (mediaThread != null && mediaThread.isAlive()){  
  68.             return false;  
  69.         }  
  70.           
  71.         return true;  
  72.     }  
  73.       
  74.     private  boolean scanMusic(IMediaScanListener listener, ICancelScanMedia cancelObser) throws Exception {  
  75.           
  76.         Cursor cursor = mContext.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,   
  77.                 AUDIO_COLUMN_STRS,   
  78.                 null,   
  79.                 null,  
  80.                 AUDIO_DISPLAYHNAME);                  
  81.   
  82.         if (cursor != null)  
  83.         {  
  84.             int count = cursor.getCount();  
  85.             if (count != 0)  
  86.             {  
  87.                 int _name_index = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME);  
  88.                 int _dir_index = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);  
  89.                 if (cursor.moveToFirst()) {    
  90.                     do {   
  91.                         if (cancelObser.ifCancel()){  
  92.                             return false;  
  93.                         }  
  94.                         String srcpath = cursor.getString(_dir_index);  
  95.                         String name = cursor.getString(_name_index);  
  96.                         listener.mediaScan(AUDIO_TYPE, srcpath, name);  
  97.                   
  98.                     } while (cursor.moveToNext());    
  99.                 }             
  100.             }         
  101.             cursor.close();  
  102.             return true;  
  103.         }  
  104.   
  105.         return false;  
  106.     }  
  107.       
  108.     private  boolean scanVideo(IMediaScanListener listener, ICancelScanMedia cancelObser) throws Exception {  
  109.           
  110.         Cursor cursor = mContext.getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,   
  111.                 VIDEO_COLUMN_STRS,   
  112.                 null,   
  113.                 null,  
  114.                 VIDEO_DISPLAYHNAME);                  
  115.   
  116.         if (cursor != null)  
  117.         {  
  118.             int count = cursor.getCount();  
  119.             if (count != 0)  
  120.             {  
  121.                 int _name_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME);  
  122.                 int _dir_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);  
  123.                 if (cursor.moveToFirst()) {    
  124.                     do {   
  125.                         if (cancelObser.ifCancel()){  
  126.                             return false;  
  127.                         }  
  128.                         String srcpath = cursor.getString(_dir_index);  
  129.                         String name = cursor.getString(_name_index);  
  130.                         listener.mediaScan(VIDEO_TYPE, srcpath, name);  
  131.                     } while (cursor.moveToNext());    
  132.                 }             
  133.             }         
  134.             cursor.close();  
  135.             return true;  
  136.         }  
  137.   
  138.         return false;  
  139.     }  
  140.       
  141.     private  boolean scanImage(IMediaScanListener listener, ICancelScanMedia cancelObser) throws Exception {  
  142.           
  143.         Cursor cursor = mContext.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,   
  144.                 IMAGE_COLUMN_STRS,   
  145.                 null,   
  146.                 null,  
  147.                 IMAGE_DISPLAYHNAME);                  
  148.   
  149.         if (cursor != null)  
  150.         {  
  151.             int count = cursor.getCount();  
  152.             if (count != 0)  
  153.             {  
  154.                 int _name_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME);  
  155.                 int _dir_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);  
  156.                 if (cursor.moveToFirst()) {    
  157.                     do {   
  158.                         if (cancelObser.ifCancel()){  
  159.                             return false;  
  160.                         }  
  161.                         String srcpath = cursor.getString(_dir_index);  
  162.                         String name = cursor.getString(_name_index);  
  163.                         listener.mediaScan(IMAGE_TYPE, srcpath, name);  
  164.                
  165.                     } while (cursor.moveToNext());    
  166.                 }             
  167.             }         
  168.             cursor.close();  
  169.             return true;  
  170.         }  
  171.   
  172.         return false;  
  173.     }  
  174.       
  175.       
  176.     public class ScanMediaThread extends Thread implements ICancelScanMedia{  
  177.           
  178.         IMediaScanListener mListener;  
  179.         boolean exitFlag = false;  
  180.           
  181.         public ScanMediaThread(IMediaScanListener listener){  
  182.             mListener = listener;  
  183.         }  
  184.   
  185.         public void exit(){  
  186.             exitFlag = true;  
  187.         }  
  188.           
  189.         @Override  
  190.         public void run() {  
  191.   
  192.             try {  
  193.                 scanMusic(mListener, this);  
  194.                 scanVideo(mListener, this);  
  195.                 scanImage(mListener, this);  
  196.             } catch (Exception e) {  
  197.                 e.printStackTrace();  
  198.             }  
  199.               
  200.             super.run();  
  201.         }  
  202.   
  203.         @Override  
  204.         public boolean ifCancel() {  
  205.             return exitFlag;  
  206.         }     
  207.     }  
  208.       
  209.       
  210.     public  interface ICancelScanMedia{  
  211.         public boolean ifCancel();  
  212.     }  
  213.       
  214.       
  215. }  

startServerstopServer分別對應設備的開啓關閉

startServer需要傳入的三個參數分別是根目錄,設備名和設備ID

在本地構建好web目錄後將根目錄路徑設置進去

然後開啓一個線程來瀏覽本地多媒體文件並通過創建軟鏈接來映射本地路徑和web路徑

詳看這個類:

  1. public class MediaStoreCenter implements IMediaScanListener{  
  2.   
  3.   
  4.     private static final CommonLog log = LogFactory.createLog();  
  5.       
  6.     private static  MediaStoreCenter mInstance;  
  7.     private Context mContext;  
  8.       
  9.       
  10.     private String mShareRootPath = "";  
  11.     private String mImageFolderPath = "";  
  12.     private String mVideoFolderPath = "";  
  13.     private String mAudioFolderPath = "";  
  14.       
  15.     private MediaScannerCenter mMediaScannerCenter;  
  16.     private Map<String, String> mMediaStoreMap = new HashMap<String, String>();  
  17.       
  18.       
  19.     private MediaStoreCenter(Context context) {  
  20.         mContext = context;  
  21.           
  22.         initData();  
  23.     }  
  24.   
  25.     public static synchronized MediaStoreCenter getInstance() {  
  26.         if (mInstance == null){  
  27.             mInstance  = new MediaStoreCenter(ServerApplication.getInstance());  
  28.         }  
  29.         return mInstance;  
  30.     }  
  31.   
  32.     private void initData(){  
  33.         mShareRootPath = mContext.getFilesDir().getAbsolutePath()+"/" + "rootFolder";  
  34.         mImageFolderPath = mShareRootPath + "/" + "Image";  
  35.         mVideoFolderPath = mShareRootPath + "/" + "Video";  
  36.         mAudioFolderPath = mShareRootPath + "/" + "Audio";  
  37.         mMediaScannerCenter = MediaScannerCenter.getInstance();  
  38.     }  
  39.       
  40.     public String getRootDir(){  
  41.         return mShareRootPath;  
  42.     }  
  43.     public void clearAllData(){  
  44.         stopScanMedia();  
  45.         clearMediaCache();  
  46.         clearWebFolder();  
  47.     }  
  48.       
  49.     public boolean createWebFolder(){  
  50.         boolean ret = FileHelper.createDirectory(mShareRootPath);  
  51.         if (!ret){  
  52.             return false;  
  53.         }  
  54.           
  55.         FileHelper.createDirectory(mImageFolderPath);  
  56.         FileHelper.createDirectory(mVideoFolderPath);  
  57.         FileHelper.createDirectory(mAudioFolderPath);  
  58.           
  59.         return true;  
  60.     }  
  61.       
  62.     public boolean clearWebFolder(){  
  63.   
  64.         long time = System.currentTimeMillis();  
  65.         boolean ret = FileHelper.deleteDirectory(mShareRootPath);  
  66.         long time1 = System.currentTimeMillis();  
  67.         log.e("clearWebFolder cost : " + (time1 - time));  
  68.         return ret;  
  69.     }  
  70.   
  71.     public void clearMediaCache(){  
  72.         mMediaStoreMap.clear();  
  73.     }  
  74.       
  75.     public void doScanMedia(){  
  76.         mMediaScannerCenter.startScanThread(this);  
  77.     }  
  78.       
  79.     public void stopScanMedia(){  
  80.         mMediaScannerCenter.stopScanThread();  
  81.         while(!mMediaScannerCenter.isThreadOver()){  
  82.             try {  
  83.                 Thread.sleep(100);  
  84.             } catch (InterruptedException e) {  
  85.                 e.printStackTrace();  
  86.             }  
  87.         }  
  88.     }  
  89.   
  90.     @Override  
  91.     public void mediaScan(int mediaType, String mediaPath, String mediaName) {  
  92.           
  93.         switch (mediaType) {  
  94.         case MediaScannerCenter.AUDIO_TYPE:  
  95.             mapAudio(mediaPath, mediaName);  
  96.             break;  
  97.         case MediaScannerCenter.VIDEO_TYPE:  
  98.             mapVideo(mediaPath, mediaName);  
  99.             break;  
  100.         case MediaScannerCenter.IMAGE_TYPE:  
  101.             mapImage(mediaPath, mediaName);  
  102.             break;  
  103.         default:  
  104.             break;  
  105.         }  
  106.           
  107.     }  
  108.       
  109.       
  110.     private void mapAudio( String mediaPath, String mediaName){  
  111.         String webPath = mAudioFolderPath + "/" + mediaName;  
  112.         mMediaStoreMap.put(mediaPath, webPath);  
  113.         softLinkMode(mediaPath, webPath);  
  114.     }  
  115.       
  116.     private void mapVideo( String mediaPath, String mediaName){  
  117.         String webPath = mVideoFolderPath + "/" + mediaName;  
  118.         mMediaStoreMap.put(mediaPath, webPath);  
  119.         softLinkMode(mediaPath, webPath);  
  120.     }  
  121.       
  122.     private void mapImage( String mediaPath, String mediaName){  
  123.         String webPath = mImageFolderPath + "/" + mediaName;  
  124.         mMediaStoreMap.put(mediaPath, webPath);  
  125.         softLinkMode(mediaPath, webPath);  
  126.     }  
  127.       
  128.       
  129.     private boolean softLinkMode(String localPath, String webPath){  
  130.         Process p;  
  131.         int status;  
  132.         try {  
  133.             long time = System.currentTimeMillis();  
  134.             String cmd = "ln -s " + localPath + " "+ webPath;  
  135.             p = Runtime.getRuntime().exec(cmd);  
  136.             releaseProcessStream(p);  
  137.               
  138.             status = p.waitFor();         
  139.             if (status == 0) {  
  140.                 return true;//success  
  141.             } else {  
  142.                 log.e("status = " + status + ", run ln -s failed !localPath = " + localPath);  
  143.                 return false;  
  144.             }  
  145.         }catch (Exception e) {  
  146.             log.e("Catch Exceptino run ln -s failed !localPath = " + localPath);  
  147.             return false;  
  148.         }  
  149.     }  
  150.       
  151.     private void releaseProcessStream(Process p) throws IOException{  
  152.         InputStream stderr = p.getErrorStream();  
  153.         InputStreamReader isr = new InputStreamReader(stderr);  
  154.         BufferedReader br = new BufferedReader(isr);  
  155.         String line = null;  
  156.         while ( (line = br.readLine()) != null)  
  157.             System.out.println(line);  
  158.     }  
  159. }  

這樣控制點訪問的時候就可以瀏覽到多媒體文件了

關鍵代碼大都已經貼出來了,詳情大家down code去了解吧 

Github下載頁:https://github.com/geniusgithub/MediaServer


當然關於android上的DMS實現網上已有一個不錯的開源項目wireme

下載地址 http://code.google.com/p/wireme/

用的是cling庫,下載鏈接https://github.com/4thline/cling


不過Platinum庫在穩定性方面還是要勝過其它java庫的,而且效率也高,所以推薦大家使用

DLNA開發文檔鏈接:http://download.csdn.net/detail/geniuseoe2012/4969961


more brilliant,Please pay attention to my CSDN blog -->http://blog.csdn.net/geniuseoe2012  

發佈了0 篇原創文章 · 獲贊 0 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章