2016-03-06 136 views
0

我有一個IP攝像機(高清無線N立方網絡攝像機 - D-LINK),我試圖使用一個應用程序流我開發的問題是我收到以下錯誤我看到的只是一個黑屏。Android rtsp從網絡攝像機直播視頻不工作

03-06 16:00:33.434 22670-22670/com.shai.ipcamdemo W/MediaPlayer: Couldn't open file on client side; trying server side: java.io.FileNotFoundException: No content provider: rtsp://xx.xx.xx.151:554/live1.sdp 

03-06 16:00:33.451 22670-22682/com.shai.ipcamdemo W/MediaPlayer: info/warning (701, 0) 

03-06 16:00:35.297 22670-22682/com.shai.ipcamdemo W/AudioSystem: AudioFlinger server died! 

03-06 16:00:35.297 22670-22681/com.shai.ipcamdemo W/IMediaDeathNotifier: media server died 

03-06 16:00:35.297 22670-22681/com.shai.ipcamdemo E/MediaPlayer: error (100, 0) 

03-06 16:00:35.298 22670-22670/com.shai.ipcamdemo E/MediaPlayer: Error (100,0) 

這是視頻配置:D-Link config我正在測試Nexus 5設備。

我知道類似的問題已被問到,但我還沒有找到相同的或可以幫助我的問題。

public class MainActivity extends Activity implements MediaPlayer.OnPreparedListener, SurfaceHolder.Callback{ 

    final static String USERNAME = "admin"; 
    final static String PASSWORD = "xxxxx"; 
    final static String RTSP_URL = "rtsp://xx.xx.xx.151:554/live1.sdp"; 

    private MediaPlayer _mediaPlayer; 
    private SurfaceHolder _surfaceHolder; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     Window window = getWindow(); 
     window.setFlags(
       WindowManager.LayoutParams.FLAG_FULLSCREEN, 
       WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     window.setBackgroundDrawableResource(android.R.color.black); 

     setContentView(R.layout.activity_main); 

     // Configure the view that renders live video. 
     SurfaceView surfaceView = 
       (SurfaceView) findViewById(R.id.surfaceView); 
     _surfaceHolder = surfaceView.getHolder(); 
     _surfaceHolder.addCallback(this); 
     _surfaceHolder.setFixedSize(320, 240); 
    } 

    @Override 
    public void surfaceCreated(SurfaceHolder holder) { 
     _mediaPlayer = new MediaPlayer(); 
     _mediaPlayer.setDisplay(_surfaceHolder); 

     Context context = getApplicationContext(); 
     Map<String, String> headers = getRtspHeaders(); 
     Uri source = Uri.parse(RTSP_URL); 

     try { 
      // Specify the IP camera's URL and auth headers. 
      _mediaPlayer.setDataSource(context, source, headers); 

      // Begin the process of setting up a video stream. 
      _mediaPlayer.setOnPreparedListener(this); 
      _mediaPlayer.prepareAsync(); 
     } 
     catch (Exception e) {} 
    } 

    @Override 
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { 
    } 

    @Override 
    public void surfaceDestroyed(SurfaceHolder holder) { 
     _mediaPlayer.release(); 
    } 

    @Override 
    public void onPrepared(MediaPlayer mp) { 
     _mediaPlayer.start(); 
    } 

    private Map<String, String> getRtspHeaders() { 
     Map<String, String> headers = new HashMap<String, String>(); 
     String basicAuthValue = getBasicAuthValue(USERNAME, PASSWORD); 
     headers.put("Authorization", basicAuthValue); 
     return headers; 
    } 

    private String getBasicAuthValue(String usr, String pwd) { 
     String credentials = usr + ":" + pwd; 
     int flags = Base64.URL_SAFE | Base64.NO_WRAP; 
     byte[] bytes = credentials.getBytes(); 
     return "Basic " + Base64.encodeToString(bytes, flags); 
    } 
} 

清單

<?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.shai.ipcamdemo"> 

     <uses-permission android:name="android.permission.INTERNET" /> 
     <uses-permission android:name="android.permission.RECORD_AUDIO" /> 

     <application 
      android:allowBackup="true" 
      android:icon="@mipmap/ic_launcher" 
      android:label="@string/app_name" 
      android:supportsRtl="true" 
      android:theme="@style/AppTheme"> 
      <activity android:name=".MainActivity"> 
       <intent-filter> 
        <action android:name="android.intent.action.MAIN" /> 

        <category android:name="android.intent.category.LAUNCHER" /> 
       </intent-filter> 
      </activity> 
     </application> 

    </manifest> 

佈局

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.shai.ipcamdemo.MainActivity"> 

<SurfaceView 
    android:id="@+id/surfaceView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 
</RelativeLayout> 
+0

也許我不能流H.264格式直? –

回答

0

的問題是並非所有的Android設備支持.sdp轉移:(

相關問題