Chapter 6: Jam! Implementing Audio in Android Apps.

Slides:



Advertisements
Similar presentations
Google Android Introduction to Mobile Computing. Android is part of the build a better phone process Open Handset Alliance produces Android Comprises.
Advertisements

Chapter 1: Voilà! Meet the Android
Chapter 3: Engage! Android User Input, Variables, and Operations
Mobile Computing Lecture#13. Lecture Contents 2 Widgets  Creating App Widget  Unsupported/Supported Views/Layouts  Widget Layout  Widget Settings.
Chapter 6 Jam! Implementing Audio in Android Apps.
WIDGET PLAYER STEPHEN NEWBY. WHAT ARE WIDGETS? Widgets are placed on the Android device’s home screen Can be added, removed, resized, moved at will Stay.
The Android Activity Lifecycle. Slide 2 Introduction Working with the Android logging system Rotation and multiple layouts Understanding the Android activity.
Chapter 11: Discover! Incorporating Google Maps
Filip Debelić What is it? Android is a mobile operating system (OS) based on the Linux kernel and currently developed by Google Android,
A Guide to Oracle9i1 Creating an Integrated Database Application Chapter 8.
Android Development (Basics)
Basic Audio and Video. Audio Primary components – Audio file stored in ‘raw’ folder within ‘res’ folder ‘raw’ directory must be created while many formats.
CS378 - Mobile Computing Anatomy of an Android App and the App Lifecycle.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Chapter 1: Voilà! Meet the Android. Smartphones –Can browse the Web –Allow you to play games –Use business applications –Check –Play music –Record.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 9: Customize! Navigating with a Master/Detail.
Introducing the Sudoku Example
 Understanding an activity  Starting an activity  Passing information between activities  Understanding intents  Understanding the activity lifecycle.
CS5103 Software Engineering Lecture 08 Android Development II.
Chapter 12: Finale! Publishing Your Android App. Objectives In this chapter, you learn to: Understand Google Play Target various device configurations.
Chapter 5: Investigate! Lists, Arrays, and Web Browsers.
Chapter 9: Customize! Navigating with Tabs on a Tablet App.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Chapter 1: Voilà! Meet the Android
Chapter 10: Move! Creating Animation
6-2 2D Graphics CSNB544 Mobile Application Development Thanks to Utexas Austin.
McGraw-Hill/Irwin Programming in Visual Basic 6.0 © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Update Edition Chapter 6 Multiple Forms.
Favorite Twitter® Searches App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Chapter 2: Simplify! The Android User Interface
Tip Calculator App Building an Android App with Java © by Pearson Education, Inc. All Rights Reserved.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 5: Investigate! Android Lists, Arrays,
DUE Hello World on the Android Platform.
Chapter 12: Finale! Publishing Your Android App
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
Chapter 2 The Android User Interface. Objectives  In this chapter, you learn to:  Develop a user interface using the TextView, ImageView, and Button.
INTRODUCTION TO ANDROID. Slide 2 Application Components An Android application is made of up one or more of the following components Activities We will.
Engage! Android User Input, Variables,
SpotOn Game App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 7: Reveal! Displaying Pictures in a GridView.
Android Boot Camp for Developers Using Java, 3E
Chapter 7: Reveal! Displaying Pictures in a Gallery.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 2: Simplify! The Android User Interface.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
Android Hello World 1. Click on Start and type eclipse into the textbox 2.
Field Trip #32 Digital Alarm Clock By Keith Lynn.
Playing an MP3 Music File in Conjunction With a PowerPoint 2010 Presentation Victoria Ricciardiello December 2012.
First Venture into the Android World Chapter 1 Part 2.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
CS378 - Mobile Computing Audio.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
1 Android Development Lean and mean introduction Based on a presentation by Mihail L. Sichitiu.
Services Background operating component without a visual interface Running in the background indefinitely Differently from Activity, Service in Android.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 10: Move! Creating Animation 1 Android.
School of Engineering and Information and Communication Technology KIT305/KIT607 Mobile Application Development Android OS –Permissions (cont.), Fragments,
The Ingredients of Android Applications. A simple application in a process In a classical programming environment, the OS would load the program code.
Chapter 5: Investigate! Lists, Arrays, and Web Browsers.
Chapter 2: Simplify! The Android User Interface
Android Boot Camp for Developers Using Java, 3E
The Android Activity Lifecycle
Chapter 1: An Introduction to Visual Basic 2015
Using Procedures and Exception Handling
Android Topics Android Activity Lifecycle and Experiment Toast
Android Topics Threads and the MessageQueue
Activities, Fragments, and Intents
Presentation transcript:

Chapter 6: Jam! Implementing Audio in Android Apps

Objectives In this chapter, you learn to: Create an Android project using a splash screen Design a TextView control with a background image Pause the execution of an Activity with a timer Understand the Activity life cycle Open an Activity with onCreate( ) End an Activity with finish( ) Assign class variables Create a raw folder for music files 2 Android Boot Camp for Developers using Java

Objectives (continued) Play music with a MediaPlayer method Start and resume music playback using the start and pause methods Change the Text property of a control Change the visibility of a control 3 Android Boot Camp for Developers using Java

Implementing Audio The most common Smartphone activities –Texting –Talking –Gaming –Playing Music 4 Android Boot Camp for Developers using Java Figure 6-1 Eastern Music Android app Figure 6-2 Music played in the Android app

Implementing Audio (continued) Steps to complete the app: 1.Create a splash screen with a timer. 2.Design a TextView control with a background image. 3.Initialize a TimerTask and a timer. 4.Launch a second Activity. 5.Design a second XML layout. 6.Add music files to the raw folder. 7.Initialize the MediaPlayer class. 8.Play and pause music with a Button control. 5 Android Boot Camp for Developers using Java

Creating a Splash Screen –A Splash Screen is a window that is displayed for approximately 5 seconds when the app opens –The next screen opens automatically –The Android initializes its resources and loads necessary files while the splash screen is displayed 6 Android Boot Camp for Developers using Java

Creating a Splash Screen (continued) 7 Android Boot Camp for Developers using Java Adding a Background Image to a TextView Widget Image is not an ImageView Widget Use a TextView widget with a background image Figure 6-5 splash.xml displays a TextView control

Creating a List (continued) Creating an Timer –A timer in Java can: Execute a one-time task like displaying a splash screen Perform a continuous process such as a morning wake-up call set to run at regular intervals –Use two Java classes, named TimerTask and Timer –Each time a timer runs it runs in a single thread A thread is a single sequential flow of control within a program 8 Android Boot Camp for Developers using Java

Creating a List (continued) Creating a Timer –Code to create a Timer: TimerTask task = new TimerTask() public void run() { // TODO Auto-generated method stub } 9 Android Boot Camp for Developers using Java

Creating a Splash Screen (continued) 10 Android Boot Camp for Developers using Java Figure 6-6 setContentView and Timer task statements Figure 6-7 run() method

Creating a Splash Screen (continued) Scheduling a Timer –Timers are scheduled in milliseconds –5000 milliseconds = 5 seconds 11 Android Boot Camp for Developers using Java Figure 6-9 Timer scheduled

Creating a Splash Screen (continued) Life and Death of an Activity –Each activity has a life cycle – a series of actions from the beginning of an Activity until its end –When the activity begins, we use an onCreate() method to load it into memory –When the activity ends, we use an onDestroy() method to remove it from memory –Four states of an Activity: Active Pause Stopped Dead 12 Android Boot Camp for Developers using Java

Creating a Splash Screen (continued) 13 Android Boot Camp for Developers using Java Figure 6-1 methods used in the life cycle of an Activity

Creating a Splash Screen (cont’d) 14 Android Boot Camp for Developers using Java Figure 6-10 Activity life cycle Ovals represent major states of the Activity Rectangles represent methods that can be implemented to perform operations

Launching the Next Activity –After the Splash Screen is destroyed an intent must request that the next Activity is launched –Main.xml already exists as the default layout –A second class named Main must be created before the code can launch this Java class –Android manifest file must be updated to include the Main Activity –Main Activity is responsible for playing music 15 Android Boot Camp for Developers using Java

Launching the Next Activity (continued) 16 Android Boot Camp for Developers using Java Figure 6-12 Main class created Figure 6-13 Adding the Main Activity Figure 6-14 Intent statement

Designing the main.xml File 17 Android Boot Camp for Developers using Java Figure 6-15 ImageView and Button controls in main.xml Figure 6-16 main.xml layout complete

Designing the main.xml File (continued) Class Variables –Recall that local variables are declared within a method –The scope of a variable refers to the variable’s visibility within a class –When a variable is needed in multiple methods in a class, a global variable is used –Global variables are called class variables 18 Android Boot Camp for Developers using Java

Designing the main.xml File (continued) 19 Android Boot Camp for Developers using Java Figure 6-17 Class variables Figure 6-18 onCreate method

Designing the main.xml File (continued) 20 Android Boot Camp for Developers using Java Figure 6-19 Button controls referenced

Designing the main.xml File (continued) 21 Android Boot Camp for Developers using Java Figure 6-20 Inserting the first Button OnClickListener stub

Playing Music –Android phones and tablets have built-in music players –Androids can play audio and video from several data sources –.mp3 files are most common –Can also play.wav,.ogg, and.midi –Uses codec technology to compress and decompress files 22 Android Boot Camp for Developers using Java

Creating a Raw Folder for Music Files 23 Android Boot Camp for Developers using Java Figure 6-22 New Folder dialog box Figure 6-23 Music Files in the raw folder

–A MediaPlayer class provides the methods to control audio playback on Android devices MediaPlayer mpBamboo = MediaPlayer.create(this, R.raw.bamboo); 24 Android Boot Camp for Developers using Java Using the MediaPlayer Class Figure 6-24 MediaPlayer instance statements

The MediaPlayer State 25 Android Boot Camp for Developers using Java Using the MediaPlayer Class (continued) Table 6-2 Common MediaPlayer states

26 Android Boot Camp for Developers using Java Using the MediaPlayer Class (continued) switch(playing) { case 0: mpBamboo.start(); playing = 1; break; case 1: mpBamboo.pause(); playing = 0; break; } Recall the switch statement:

Using the MediaPlayer Class (continued) 27 Android Boot Camp for Developers using Java Figure 6-26 Switch statements for both onClick methods

Changing the Text Property Using Code btBamboo.setText("Pause Bamboo Song"); 28 Android Boot Camp for Developers using Java Using the MediaPlayer Class (continued) Figure 6-27 the setText() method changes the button control in both case statements

Changing the Visible Property Using Code –To hide the control: btBamboo.setVisibility(View.INVISIBLE); –To display the control: btBamboo.setVisibility(View.VISIBLE);Bamboo Song"); 29 Android Boot Camp for Developers using Java Using the MediaPlayer Class (continued)

Changing the Visible Property Using Code (cont’) 30 Android Boot Camp for Developers using Java Using the MediaPlayer Class (continued) Figure 6-29 the setVisibility() method changes the visibility of the Button control

31 Android Boot Camp for Developers using Java Completed code Figure 6-30 Completed code

Summary Android apps can show a splash screen that displays program name, brand logo, or author name Splash screens open when an app launches TextView widgets display a background color or image Timers in Java execute a one-time task or perform a continuous process Timers must be scheduled to run – timed in milliseconds 32 Android Boot Camp for Developers using Java

Summary (continued) Each Activity has a life cycle – a series of actions from the beginning of the activity to its end Local variables exist within a method and cease to exist when the method is finished Variable scope refers to a variable’s visibility within a class Every Android phone and tablet has a built-in music player Music files are typically stored in the res\raw subfolder 33 Android Boot Camp for Developers using Java

Summary (continued) The MediaPlayer class provides the methods to control audio playback on an Android device The Java property that controls whether a control is displayed on the emulator is the Visible property 34 Android Boot Camp for Developers using Java