Lecture 7: Service Topics: Services, Playing Media.

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

Services. Application component No user interface Two main uses Performing background processing Supporting remote method execution.
Global MP3 Geoffrey Beers Deborah Ford Mike Quinn Mark Ridao.
CSE2102 Introduction to Software Engineering Lab 2 Sept/4/2013.
Group 8: Dylan Lentini (AE), Mandy Minuti (WSE), Jean Paul Galea (TL)
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.
Chapter 6: Jam! Implementing Audio in Android Apps.
Mobile Application Development
CS371m - Mobile Computing Audio.
Android Middleware Bo Pang
Basic Audio and Video. Audio Primary components – Audio file stored in ‘raw’ folder within ‘res’ folder ‘raw’ directory must be created while many formats.
Multimedia.
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Content Providers & Services.
Rajab Davudov. Agenda Eclipse, ADT and Android SDK APK file Fundamentals – Activity – Service – Content Provider – Broadcast Receiver – Intent Hello World.
COMP 365 Android Development.  Perform operations in the background  Services do not have a user interface (UI)  Can run without appearing on screen.
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit
DUE Hello World on the Android Platform.
16 Services and Broadcast Receivers CSNB544 Mobile Application Development Thanks to Utexas Austin.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Recitation.
10/10/2015 E.R.Edwards 10/10/2015 Staffordshire University School of Computing Introduction to Android Overview of Android System Android Components Component.
Working in the Background Radan Ganchev Astea Solutions.
Android 13: Services and Content Providers Kirk Scott 1.
Services A Service is an application component that can perform long-running operations in the background and does not provide a user interface. An application.
DKU-MUST Mobile ICT Education Center 10. Activity and Intent.
CS378 - Mobile Computing Audio.
Services Background operating component without a visual interface Running in the background indefinitely Differently from Activity, Service in Android.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Android Programming Steve Ko Computer Sciences and Engineering University at Buffalo.
Multimedia. Audio,vedio and Images End user typically refer to vedio/audio using the respective file format MP4 or AVI(audio vedio interleave) Developer.
Lecture 2: Android Concepts
Lecture 6: Process and Threads Topics: Process, Threads, Worker Thread, Async Task Date: Mar 1, 2016.
Speech Service & client(Activity) 오지영.
Lecture 7: Media Player Topics: Media Player, Async prepare Date: Mar 3, 2016.
Services. What is a Service? A Service is not a separate process. A Service is not a thread. A Service itself is actually very simple, providing two main.
CS371m - Mobile Computing Audio. Audio on Device Devices have multiple audio streams: – music, alarms, notifications, incoming call ringer, in call volume,
Developing Android Services. Objectives Creating a service that runs in background Performing long-running tasks in a separate thread Performing repeated.
Introduction to Android Programming
Audio and Haptic Feedback
Android Application -Architecture.
Android Application Audio 1.
Lecture 2: Android Concepts
Broadcast receivers.
CS371m - Mobile Computing Services and Broadcast Receivers
Lecture 2 Zablon Ochomo Android Programming Lecture 2 Zablon Ochomo
Instructor: Mazhar Hussain
Lecture 7: Android Services
Android Boot Camp for Developers Using Java, 3E
Mobile Application Development BSCS-7 Lecture # 6
Anatomy of an Android App and the App Lifecycle
Android Mobile Application Development
Lecture 7: Media Player Topics: Media Player, Async prepare
Lecture 6: Process, Thread, Task
The Android Activity Lifecycle
Android Application Development android.cs.uchicago.edu
Android Programming Lecture 9
Developing Android Services
Windows Phone multitasking
Anatomy of an Android App and the App Lifecycle
Application Development A Tutorial Driven Course
Android Topics Android Activity Lifecycle and Experiment Toast
Android Topics UI Thread and Limited processing resources
CS323 Android Topics Network Basics for an Android App
Service Services.
Lecture 7: Service Topics: Services, Broadcast Receiver, Playing Media.
SE4S701 Mobile Application Development
Lecture 6: Process, Thread, Task
Mobile Programming Dr. Mohsin Ali Memon.
Android Development Tools
CIS 470 Mobile App Development
Presentation transcript:

Lecture 7: Service Topics: Services, Playing Media

Today’s class: Concepts What is a Service? (Lecture) Types, ways to interact. Questions (code) How do we create + start a service? Example PrimalityTest service. Concepts (lecture) How do we play music in Android? Sync, Async, and Service! Example (code) Create a music player. Use Async prepare and a service.

Concepts

Service A UI less component that runs in the background to perform (long-running) operations. Example: Sensors, location, power, battery, etc. Power manage: wake lock, reboot. Settings>Developer Options>Running Services

Custom Service We can create our own service. Power manage: wake lock, reboot.

Types of Services Foreground and Background Services noticeable to users must show notification not noticeable to users only foreground apps can start

Types of Services Bounded and Unbounded Services Bound Service bindService() Request/Response Bound Service (dies when #clients = 0) Power manage: wake lock, reboot. Client (e.g. an activity)

Types of Services Bounded and Unbounded Services Unbounded Service startService() broadcasts Unbounded Service (stopped explicitly) Power manage: wake lock, reboot. Client (e.g. an activity)

Service Runs In … Services run in the main thread of its hosting process. start start Power manage: wake lock, reboot. T2 T1 T1 Default What You Should Do

How do you create a Custom Service? Question #1 How do you create a Custom Service?

How do you start a Service? Question #2 How do you start a Service?

Creating a Custom Service Extend a service and override some callbacks. Caution: Don’t forget to declare it in the manifest. Custom Service: extends Service/IntentService onCreate() startService() onStartCommand() Component X: bindService() onBind() Similar to CustomView, but … Component Y: onDestroy()

Service Lifecycle Q. Who stops a Service? Two execution paths for startService() and bindService(): Q. Who stops a Service? Power manage: wake lock, reboot.

Coding Example Create a custom service by extending Service that tests primality of a number. Use Intents to illustrate that it works. How do we get results back? Activity Service startService(Intent) Notification, Toast Broadcast Receiver sendBroadcast(Intent)

Playing Media

Media Playback Play Audio/Video from: Support for Output Devices: Application Resources (raw resource) File System Data Stream over a Network. Support for Output Devices: Speaker Bluetooth Headset However, you cannot play sound files in the conversation audio during a phone call.

Media Playback API Two important classes – MediaPlayer AudioManager stop, play, pause … AudioManager volume, ringer mode (mute, vibrate) …

Using Media Player API Permissions: INTERNET, WAKE_LOCK, STORAGE Playing from Local Resource: Playing from a Local Uri:

Using Media Player API Playing from an Internet URL Must be progressively downloadable Supported media format: http://developer.android.com/guide/appendix/media-formats.html

Media Player State Diagram

Asynchronous Preparation For files: It is “OK” to use prepare() For streams: You should always use prepareAsync() Implement MediaPlayer.OnPreparedListener mp.setOnPreparedListener(this); public void onPrepared(MediaPlayer mp) { mp.start(); } BLOCKING NON- BLOCKING

Using Wake Locks When device sleeps, the system tries to shut off features that are not necessary – including CPU and WiFi hardware. Use “Wake Locks” to let the system know you need some features even if the phone is idle. mp.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK); WifiManager.WifiLock wifiLock = ((WifiManager) getSystemService(Context.WIFI_SERVICE)) .createWifiLock(WifiManager.WIFI_MODE_FULL, "mylock"); wifiLock.acquire();

Playing songs in a background service

Code practice Create a MediaPlayer and play a song. Modify the code to prepare a media player asynchronously.

References (study these) https://developer.android.com/guide/components/services.html http://developer.android.com/guide/topics/media/mediaplayer.html http://developer.android.com/images/mediaplayer_state_diagram.gif