2013-08-06 78 views
-1

我使用Android上的RTMP下載一個流。如果我第一次運行庫時一切正常。第二次該應用程序不啓動RTMP下載:/加載本機庫兩次

我搜索了最近三天,知道我無法加載本地庫兩次或只是卸載它,並且我有三個選項來處理我的問題:

  1. 使用自定義的類裝載器(後仍然加載System.gc()的庫)
  2. 運行在自己的進程服務(它沒有工作的圖書館仍然在殺害後服務加載)。
  3. 編寫一個本地庫,通過dlopen加載RTMP庫並通過dlclose關閉它。

我不知道任何進一步的選項:/我甚至不知道怎麼寫本機庫加載其他庫:/

我用這個RTMP轉儲:https://github.com/eschriek/rtmpdump-android

回答

0

OK ,我發現找到了一種方法來做到這一點:)也許這不是一個美麗的一個,但它工作正常:

  1. 創建服務:

    在AndroidManifest
  2. 註冊爲具有這些屬性

    服務
    android:name=".rtmpdumpService" 
    android:exported="false" 
    android:process=":rtmp"
  3. 啓動服務:

    Intent rtmpdumpIntent = new Intent(getApplicationContext(), rtmpdumpService.class); 
          eSendIntent.putExtra("rtmp", "RTMP CODE"); 
          startService(rtmpdumpIntent); 
    

有時候,你不得不等待,直到它完成:

的售後服務(startService(rtmpdumpIntent):

do { 
    try { 
     Thread.sleep(500); 
    } 
    catch (InterruptedException e) { 
     //Log 
    } 
} while(isServiceRunning(rtmpdumpService.class) == true); 

isServiceRunning功能:

private boolean isServiceRunning(Class cl) { 
     ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); 
     for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { 
      if (cl.getName().equals(service.service.getClassName())) { 
       return true; 
      } 
     } 
     return false; 
    }