Embedding Video in an Android app!

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,

Screenshot_2014-09-23-20-03-09

and

Screenshot_2014-09-23-20-03-46

Thats it! no need of any special permissions in manifest at all.
Source code is available at github.
Enjoy! Happy Coding!!!

--

--

Learnings of Embedded systems, Android and Machine Learnings
Learnings of Embedded systems, Android and Machine Learnings

Published in Learnings of Embedded systems, Android and Machine Learnings

Write up of challenges, and interesting experiences happened in my day-to-day professional life

Mohammed Audhil
Mohammed Audhil

Written by Mohammed Audhil

Software Engineer @Blackhawk_Networks | more: https://github.com/Audhil (Pray. Eat. Code. Sleep.)

No responses yet