- Prepare stream video from Raspberry Pi with Camera Module. Refer to my another blog post about Raspberry Pi "Stream Raspberry Pi Camera Module video using raspivid and vlc".
- Once stream video is playing, run this example, enter the IP of Raspberry Pi and assigned port.
activity_main.xml
<LinearLayout 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"
android:orientation="vertical"
tools:context="com.example.androidmediaplayer.MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:autoLink="web"
android:text="http://android-er.blogspot.com/"
android:textStyle="bold" />
<EditText
android:id="@+id/addr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="http://192.168.xxx.xxx:8090" />
<Button
android:id="@+id/connect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Connect" />
<VideoView
android:id="@+id/streamview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
MainActivity.java
package com.example.androidmediaplayer;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;
import android.net.Uri;
import android.os.Bundle;
public class MainActivity extends ActionBarActivity {
EditText addrField;
Button btnConnect;
VideoView streamView;
MediaController mediaController;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addrField = (EditText)findViewById(R.id.addr);
btnConnect = (Button)findViewById(R.id.connect);
streamView = (VideoView)findViewById(R.id.streamview);
btnConnect.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
String s = addrField.getEditableText().toString();
playStream(s);
}});
}
private void playStream(String src){
Uri UriSrc = Uri.parse(src);
if(UriSrc == null){
Toast.makeText(MainActivity.this,
"UriSrc == null", Toast.LENGTH_LONG).show();
}else{
streamView.setVideoURI(UriSrc);
mediaController = new MediaController(this);
streamView.setMediaController(mediaController);
streamView.start();
Toast.makeText(MainActivity.this,
"Connect: " + src,
Toast.LENGTH_LONG).show();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
streamView.stopPlayback();
}
}
Permission of "android.permission.INTERNET" is needed in AndroidManifest.xml.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidmediaplayer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Download the files.
Or try the APK Here.
Updated@2016-07-06:
- Re-test on Raspberry Pi 3 + Camera Module V2 NoIR + Raspbian Jessie, play in Windows 10 + VLC Media Player and Android App with VideoView (with APK download).