I'm trying to stream the part of my desktop to my Android device.
I create stream by means of VLC media player. I construct H.264 stream with 2048 Kb/sec and 30 fps, pack it into mp4/mov container and publish it like this: rtsp://[my-ip]:[port]/stream. It is important that I don't wanna simply stream the file from the media server, but I want to make live translation of my desktop available via stream with properties, described above.
According to Android documentation from here http://developer.android.com/guide/appendix/media-formats.html it must be possible to consume H.264 video over RTSP stream on Android device (my device runs on 4.2).
But my VideoView widget says that video not found, while I can actually see my stream from another PC by means of VLC player installed here. So how can I achieve my initial goal?
Here is my Android application code:
main_layout.xml:
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<VideoView
android:id="@+id/videoRectangle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="100dp" />
<Button
android:id="@+id/connectToVideoServerButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/videoRectangle"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:text="Присоединиться" />
<EditText
android:id="@+id/streamServerAddress"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignBaseline="@+id/connectToVideoServerButton"
android:layout_alignBottom="@+id/connectToVideoServerButton"
android:layout_marginLeft="30dp"
android:layout_toRightOf="@+id/connectToVideoServerButton"
android:ems="10"
android:hint=""
android:text="" >
<requestFocus />
</EditText>
</RelativeLayout>
MainActivity.java:
package com.example.videostreamerclient;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.VideoView;
public class MainActivity extends Activity {
private VideoView videoView;
private Button videoServerConnectBtn;
private EditText streamServerAddress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView = (VideoView) findViewById(R.id.videoRectangle);
streamServerAddress = (EditText) findViewById(R.id.streamServerAddress);
videoServerConnectBtn = (Button) findViewById(R.id.connectToVideoServerButton);
videoServerConnectBtn.setOnClickListener(videoServerConnectBtnClicked);
}
private View.OnClickListener videoServerConnectBtnClicked = new View.OnClickListener() {
@Override
public void onClick(View v){
if ( streamServerAddress.getText().toString() != "" )
{
videoView.setVideoPath( streamServerAddress.getText().toString() );
videoView.start();
}
}
};
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}