Embedding Video in an Android app!
1 min readSep 27, 2014
I was in need of embedding video in an app. Its pretty simple refer this.
Go ahead with my blog or else refer the link provided.
1) Create a res/raw/ folder
2) Paste video inside raw/ folder.
3) Create a layout file activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.wordpress.smdaudhilbe.aembeddingvideoinapp.MainActivity"
tools:ignore="MergeRootFrame">
<VideoView
android:id="@+id/videoView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
4)
public class MainActivity extends Activity {
private VideoView videoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView = (VideoView) findViewById(R.id.videoView1);
// refer Video
String fileName = "android.resource://" + getPackageName() + "/" + R.raw.moto_x_review_2014;
videoView.setVideoURI(Uri.parse(fileName));
// start video
videoView.start();
}
}
Here screenshots,
and
Thats it! no need of any special permissions in manifest at all.
Source code is available at github.
Enjoy! Happy Coding!!!