<uses-permission android:name="android.permission.internet"/>

Similar documents
Mobile Application Development Lab [] Simple Android Application for Native Calculator. To develop a Simple Android Application for Native Calculator.

MAD ASSIGNMENT NO 3. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

MAD ASSIGNMENT NO 2. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

App Development for Smart Devices. Lec #7: Audio, Video & Telephony Try It Out

Android Apps Development for Mobile and Tablet Device (Level I) Lesson 2

Vienos veiklos būsena. Theory

Create Parent Activity and pass its information to Child Activity using Intents.

Android Programs Day 5

Intents. Your first app assignment

Applied Cognitive Computing Fall 2016 Android Application + IBM Bluemix (Cloudant NoSQL DB)

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Switching UIs

CSE 660 Lab 7. Submitted by: Arumugam Thendramil Pavai. 1)Simple Remote Calculator. Server is created using ServerSocket class of java. Server.

CSE 660 Lab 3 Khoi Pham Thanh Ho April 19 th, 2015

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Managing Screen Orientation

Android Workshop: Model View Controller ( MVC):

TextView Control. EditText Control. TextView Attributes. android:id - This is the ID which uniquely identifies the control.

1. Location Services. 1.1 GPS Location. 1. Create the Android application with the following attributes. Application Name: MyLocation

10.1 Introduction. Higher Level Processing. Word Recogniton Model. Text Output. Voice Signals. Spoken Words. Syntax, Semantics, Pragmatics

EMBEDDED SYSTEMS PROGRAMMING UI Specification: Approaches

Manifest.xml. Activity.java

Android Services. Victor Matos Cleveland State University. Services

INTENTS android.content.intent

Basic GUI elements - exercises

Tip Calculator. xmlns:tools=" android:layout_width="match_parent"

Terms: MediaPlayer, VideoView, MediaController,

Software Practice 3 Before we start Today s lecture Today s Task Team organization

PENGEMBANGAN APLIKASI PERANGKAT BERGERAK (MOBILE)

M.A.D ASSIGNMENT # 2 REHAN ASGHAR BSSE 15126

Fragment Example Create the following files and test the application on emulator or device.

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

ITU- FAO- DOA- TRCSL. Training on. Innovation & Application Development for E- Agriculture. Shared Preferences

Android Application Development. By : Shibaji Debnath

Our First Android Application

Tabel mysql. Kode di PHP. Config.php. Service.php

API Guide for Gesture Recognition Engine. Version 2.0

Learn about Android Content Providers and SQLite

Android Coding. Dr. J.P.E. Hodgson. August 23, Dr. J.P.E. Hodgson () Android Coding August 23, / 27

Figure 2.10 demonstrates the creation of a new project named Chapter2 using the wizard.

App Development for Smart Devices. Lec #18: Advanced Topics

IPN-ESCOM Application Development for Mobile Devices. Extraordinary. A Web service, invoking the SOAP protocol, in an Android application.

Android App Development. Mr. Michaud ICE Programs Georgia Institute of Technology

android:layout_margintop="5dp" > <EditText android:layout_width="210dp"

Starting Another Activity Preferences

Developed and taught by well-known Contact author and developer. At public for details venues or onsite at your location.

Q.1 Explain the dialog and also explain the Demonstrate working dialog in android.

ES E 3 3 L a L b 5 Android development

Multimedia Support Classes Playing Audio Watching Video Recording Audio

ANDROID PROGRAMS DAY 3

Android UI Development

M.A.D Assignment # 1

LifeStreet Media Android Publisher SDK Integration Guide

COMP61242: Task /04/18

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State

Android Basics. - Bhaumik Shukla Android Application STEALTH FLASH

Workshop. 1. Create a simple Intent (Page 1 2) Launch a Camera for Photo Taking

Thread. A Thread is a concurrent unit of execution. The thread has its own call stack for methods being invoked, their arguments and local variables.

Android HelloWorld - Example. Tushar B. Kute,

Android Beginners Workshop

Lecture 14. Android Application Development


Create a local SQL database hosting a CUSTOMER table. Each customer includes [id, name, phone]. Do the work inside Threads and Asynctasks.

Simple Currency Converter

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

8/30/15 MOBILE COMPUTING. CSE 40814/60814 Fall How many of you. have implemented a command-line user interface?

Multiple Activities. Many apps have multiple activities

CS 4330/5390: Mobile Application Development Exam 1

Upon completion of the second part of the lab the students will have:

Dynamically Create Admob Banner and Interstitial Ads

Android/Java Lightning Tutorial JULY 30, 2018

Diving into Android. By Jeroen Tietema. Jeroen Tietema,

Arrays of Buttons. Inside Android

Fragments. Lecture 11

EMBEDDED SYSTEMS PROGRAMMING Application Basics

Adaptation of materials: dr Tomasz Xięski. Based on presentations made available by Victor Matos, Cleveland State University.

Data Persistence. Chapter 10

Android Apps Development for Mobile and Tablet Device (Level I) Lesson 4. Workshop

Android - JSON Parser Tutorial

App Development for Smart Devices. Lec #9: Advanced Topics

API Guide for Gesture Recognition Engine. Version 1.1

ELET4133: Embedded Systems. Topic 15 Sensors

CS 370 Android Basics D R. M I C H A E L J. R E A L E F A L L

INTRODUCTION TO ANDROID

StoppUhr. <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="start1"

UNDERSTANDING ACTIVITIES


Android Programming วรเศรษฐ ส วรรณ ก.

EMBEDDED SYSTEMS PROGRAMMING Android Services

Android DP SDK Integration Guide

COMP4521 EMBEDDED SYSTEMS SOFTWARE

else if(rb2.ischecked()) {

1 카메라 1.1 제어절차 1.2 관련주요메서드 1.3 제작철차 서피스뷰를생성하고이를제어하는서피스홀더객체를참조해야함. 매니페스트에퍼미션을지정해야한다.

Real-Time Embedded Systems

Android Intents. Notes are based on: Android Developers

Embedded Systems Programming - PA8001

Understanding Intents and Intent Filters

Embedded Systems Programming - PA8001

Notification mechanism

05. RecyclerView and Styles

android-espresso #androidespresso

android:orientation="horizontal" android:layout_margintop="30dp"> <Button android:text="button2"

Transcription:

Chapter 11 Playing Video 11.1 Introduction We have discussed how to play audio in Chapter 9 using the class MediaPlayer. This class can also play video clips. In fact, the Android multimedia framework supports a wide variety of common media types to allow users to play audio or video from various sources, such as media files or data arriving from a network, and one can easily integrate audio, video and images into an application. The class MediaPlayer is the main API for playing audio and video, while the class AudioManager manages audio sources and outputs on a device. However, unlike audio, which can be played in the background, we need to create a surface to play a video.. Like playing audio, to play video over a network, we need to request network access by adding the uses-permission statement in the manifest file AndroidManifest.xml: <uses-permission android:name="android.permission.internet"/> While playing a video, if we do not want to keep the screen from dimming or the application process from sleeping, we also need to add the wake-lock statement in the manifest file: <uses-permission android:name="android.permission.wake_lock" /> 11.2 A Simple Example We present here a simple example of playing video in Android. We call the project and application VideoDemo1, and the package video.videodemo1. We shall write two Java files, MainActivity.java and VideoViewActivity.java to play a video, and two layout files, activity main.xml and videomain main.xml to define the screen layout. We also create the directory res/raw and put the video file to be played in the directory. The following is the code of MainActivity. Its main task is to set up a button, which listens to any clicking event. When the button is clicked, a new Intent of the class VideoViewActivity is created, and a new activity of this Intent is started: Program Listing 11-1 MainActivity.java of Project VideoDemo1 - package video.videodemo1; import android.view.view.onclicklistener; import android.content.intent; import android.widget.button; import android.app.activity; import android.os.bundle; import android.view.view; public class MainActivity extends Activity { Button button; @Override protected void oncreate(bundle savedinstancestate) { 1

2 A Simple Example super.oncreate(savedinstancestate); // Get the layout from activity_main.xml setcontentview(r.layout.activity_main); // Locate the button in activity_main.xml button = (Button) findviewbyid(r.id.streambutton); // Listen to button clicks button.setonclicklistener(new OnClickListener() { public void onclick(view arg0) { // Start New Activity.class Intent intent=new Intent(MainActivity.this,VideoViewActivity.class); startactivity ( intent ); ); ------------------------------------------------------------------------ When the activity VideoViewActivity is started, the class creates a ProgressDialog object, which is a dialog that shows a progress indicator with an optional text message or view, and progress range 0..10000. It then creates a MediaController with layout defined in res/layout/videoview main.xml to play the specified video source: Program Listing 11-2 VideoViewActivity.java of Project VideoDemo1 - // VideoViewActivity.java package video.videodemo1; import android.media.mediaplayer.onpreparedlistener; import android.media.mediaplayer; import video.videodemo1.r; import android.widget.*; import android.app.*; import android.net.uri; import android.util.log; import android.os.bundle; public class VideoViewActivity extends Activity { ProgressDialog progressdialog; VideoView videoview; @Override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // Get the layout from video_main.xml setcontentview(r.layout.videoview_main); // Find your VideoView in video_main.xml layout videoview = (VideoView) findviewbyid(r.id.videoview); // Create a progressbar progressdialog = new ProgressDialog(VideoViewActivity.this); // Set progressbar title progressdialog.settitle("video Streaming");

Chapter 11 Playing Video 3 // Set progressbar message progressdialog.setmessage("loading..."); progressdialog.setindeterminate ( false ); progressdialog.setcancelable ( false ); // Show progressbar progressdialog.show(); try { // Create MediaController MediaController mediacontroller = new MediaController(VideoViewActivity.this); mediacontroller.setanchorview(videoview); //Note: omit extension here though the real filename has it Uri video=uri.parse("android.resource://video.videodemo1/raw/android"); videoview.setmediacontroller ( mediacontroller ); videoview.setvideouri(video); catch (Exception e) { Log.e("Error", e.getmessage()); e.printstacktrace(); videoview.requestfocus(); videoview.setonpreparedlistener(new OnPreparedListener() { // Close the progress bar and play the video public void onprepared(mediaplayer mp) { progressdialog.dismiss(); videoview.start(); ); ------------------------------------------------------------------------ In the example, we have hard-coded the video source, which is the 3gp video file res/raw/android.3gp. Note that we do not include the file extension.3gp in the specification. Even though the full file name is android.3gp, we just refer to it as android: Uri video = Uri.parse ("android.resource://video.videodemo1/raw/android"); Here the video file is in a local directory. If we want to play a video from a web site, we have to specify the full file name full URL path like the following example: String videourl = "http://www.forejune.com/android/videos/android.3gp"; Uri video = Uri.parse ( videourl ); The main layout file activity main.xml has nothing special. It simply defines a clicking button, similar to some of our previous examples: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/streambutton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/button" /> </LinearLayout>

4 A Simple Example The other layout file, videoview main.xml is just as simple. It defines where on the screen the video should be presented: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_height="match_parent" android:orientation="vertical" > <VideoView android:id="@+id/videoview" android:layout_height="match_parent" /> </LinearLayout> When we run this application, it will first present a UI consisting of a button for the user to click on as shown in Figure 11-1(a). When the user clicks on the button, the video is loaded and played. Figure 11-1(b) shows a frame of the video. When the video is finished, the screen is still of the VideoView. We can press the ESC key to exit the screen, returning to the parent activity, which shows the clicking button of Figure 11-1(a). Clicking on the button will play the video again. (a) Figure 11-1 UI and Output of VideoDemo1 (b)

Chapter 11 Playing Video 5