Develop Android Apps, Coding a Video Player
Next Tutorial
Adding Local Languages To Your App

Prev Page
View All Tutorials


Android Tutorial, Coding a Video Player

If you are just arriving at this page; and you are not familiar with creating Android Apps,we suggest you begin with our tutorials introduction: About Our Tutorials. From there follow along with each tutorial lesson.

COPY/PASTE CODE

First, create a java/xml android template app using AIDE, (or Android Studio). Then you can get the code for this app from the EXAMPLE CODE section on this page.
Replace the code on the pages you need to(with our tutorial code); in order to create this app.
Sometimes, new pages have to be created.
All the other coded pages in your app can remain as they are; they don't need to be changed.


This is the App - Video Player
It can play video files.
It loads and plays automatically when your app page loads.

App Photo Video Player


How To Use Video View Code Class

For this video player we are using the VideoView layout element. This code is defined in the layout file at main.xml, and then in our java class file at MyVideoPlayer.java; the VideoView method is declared and also the Media Controller method.

We define the location of our VideoView using the findViewById method.

The location of the video file to be played is also declared in the java file. All media type files are put in the res/raw folder of your app project. You have to create the folder; goto res/, and from right side in AIDE select dots, then select Create New Folder; type raw, then ok. Folder is now created. Use your device File Manager to copy paste, or move files into the raw folder of your app project.

For our video player; we are making a simple app that will play a video file when the view loads onto the screen. We did not code any buttons for this video player app; however, because we are using the VideoView and MediaController methods; Play and Pause toggle buttons will automatically show in the view when you tap on the screen. They remain visible for a few seconds.



Additional Reading at Android Developer website
Media Controller For Video View Media Formats Android

Creating - Naming Your App Using AIDE

When creating your app,(from left menu) choose:
Create New Project;
Then, choose
New Android App(gradle, android Java/xml)
or
Hello World App Java/xml
if your using the original version of AIDE

For the app name use;

VideoPlayer for the App Name and,
for the package name(next line) use:
com.aac.videoplayerexample.

Where Code is Coded - The Coded Pages

Code for the app - Video Player

For this app you will use these coded pages:

1 layout file, main.xml,(already created, just copy paste this tutorial app code into it and save); located at res/layout/.

1 java page, MyVideoPlayer.java,(already created as MainActivity.java-just rename the page to MyVideoPlayer.java, add the code from Example Code and save the file) or if you prefer:

You can just delete the MainActivity.java page;(already created for us when we made our android template app)
then just create another java page and name it MyVideoPlayer.java, and add the code from our Example Code Section, to the MyVideoPlayer.java page, and save the page.(and do camel case your java files when naming them; first letter is capped: MyVideoPlayer.java)

In our MyVideoPlayer.java file we define our layout views:
setContentView(R.layout.main); and the VideoView layout.
Also, we add the Create method for the VideoView.

1 video file - add yours at R.raw myvideo; You will have to create the raw folder, as mentioned.
Use your tablets File Manager to copy paste your video into the AppProjects/VideoPlayer/app/src/main/res/raw/ folder.


Adding Video

For this app; you can add your own video mp4 file to this app. Just add it to the res/raw folder in your app project. If you are using spacing in your video file name you must use the underscore symbol; like my_video.mp4, and use lowercase letters.

Also, put the name of the video file at MyVideoPlayer.java. You don't add the .mp4, just the file name. Where it reads 'myvideo'; replace with your video name. Then save the page.

1 strings file, strings.xml (already created) - where we define the app_name for our app. This string, app_name is created automatically for us when we created our android template app. Since we are not adding any additional text to our app view, we don't have to add any strings, therefore, we don't need to do anything on this page.

1 manifest file, AndroidManifest.xml (already created) - where we define the app's name, sdk version, launcher icon, and the app's theme. And, where we define our app's activity page; MainActivity.java. This must be defined in the Activity element in the manifest file.

This page is created automatically each time you create a new Android Java/xml app. The sdk version, launcher icon, app theme, app name attributes are all added for you when you use an Android Template Java/xml app to create your app project.(we use the template app for our tutorials).

And, you don't need to change code on this page unless:

your adding additional activity pages or changing the name of your MainActivity.java to another name;
need to change the SDK version,
need to add Internet permission,
want to change the App's Theme;
or want to add a custom launcher icon

For this app tutorial, Video Player, we changed our MainActivity.java page name to MyVideoPlayer.java; therefore, we need to add this name to the manfest file at the Activity element.
You can just copy paste the code from our Example Code section, to replace the code that's in the androidmanifest.xml file, and save the file.

FYI

Updates - Build.gradle, Target SDKs

If your using the newest edition of AIDE, the Min SDK, and Target SDK are now coded in the build.gradle of your app project. Previously they were coded in the AndroidManifest.xml.They can be coded in both files, but it is best practice now to code them in build.gradle; and if they are in both pages; the android system will preference the targets shown (coded) in the build.gradle.



EXAMPLE CODE - Code For This Tutorial

JUST copy the code for this tutorial App Name is 'VideoPlayer - located at AppProjects/VideoPlayer in AIDE, open the AIDE app, then open App Projects, THEN select the 'VideoPlayer', app from your files hierachy(left menu);
then click on any file from the app, like strings.xml Make sure at top of page, the app name 'VideoPlayer' is there next to AppProjects like so: AppProjects/VideoPlayer, then you know you have the proper App.

Once a file is in the editor, you can edit, save it, then RUN your APP, Install, and Open your app.


Make sure you SAVED EACH PAGE,(or choose automatic saving in AIDE settings) before you RUN your code. SAVE, RUN, INSTALL, OPEN, your App. Once it has been installed on your tablet, you can open it Simply by Clicking on the Android little green App Icon,with the wording 'VideoPlayer' on your tablet. It will be with your other installed apps.

If you make further changes to this App, you need to SAVE, RUN, UPDATE, INSTALL; then open the app again.

Example Code App - Video Player :
Copy Paste the Code


This free script provided by
JavaScript Kit

Share This Page


AIDE for creating Android Apps on your tablet or cell phone(android).
Free and Paid.
GoTo Aide

ANDROID STUDIO - for creating Android Apps on your desktop computer.
Free to Install and Use
Learn more - Android Studio


The Java XML files we code(example codes) and the Android Apps we create in our Free Tutorials are compatible with Android Studio and AIDE. Just choose Java XML as your Programming Language.


You May Like:
Make Sushi Rolls Taste World Wines Flavours and Aromas



AndroidAppCoding.com, All Rights Reserved