Audio and Haptic Feedback

Slides:



Advertisements
Similar presentations
“The Digital Recorder and Voice Memos” Presented by Maria E. Delgado
Advertisements

Using Multimedia on the Web Enhancing a Web Site with Sound, Video, and Applets.
CNIT 132 – Week 9 Multimedia. Working with Multimedia Bandwidth is a measure of the amount of data that can be sent through a communication pipeline each.
TouchDevelop Chapter 5-7 Chapter 5 Audio Chapter 6 Camera, Graphics and Video Chapter 7 Sensors Mengfei Ren.
David Meredith Minim David Meredith
Cosc 5/4730 Multimedia Part 1: Audio media. PLAYING AUDIO Android android.media.
ELearning Solutions eLearning Solutions The business of education is learning.
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.
The Android Activity Lifecycle. Slide 2 Introduction Working with the Android logging system Rotation and multiple layouts Understanding the Android activity.
John Meilak Reuben Sant Jason Farrugia Media API Web Science APT 2007/2008.
CS371m - Mobile Computing Audio.
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.
CS378 - Mobile Computing Speech to Text, Text to Speech, Telephony.
CS378 - Mobile Computing What's Next?. Fragments Added in Android 3.0, a release aimed at tablets A fragment is a portion of the UI in an Activity multiple.
1 Skip Cave Chief Scientist, Intervoice Inc. Multimodal Framework Proposal.
CS5103 Software Engineering Lecture 08 Android Development II.
Take a leap towards the most promising technology
Android How to Program Presented by Thomas Bucag, Rob Goodfellowe, Samantha Tomeï © by Pearson Education, Inc. All Rights Reserved.
London April 2005 London April 2005 Creating Eyeblaster Ads The Rich Media Platform The Rich Media Platform Eyeblaster.
London April 2005 London April 2005 Creating Eyeblaster Ads The Rich Media Platform The Rich Media Platform Eyeblaster.
Rujchai Ung-arunyawee Department of Computer Engineering Khon Kaen University.
CS378 - Mobile Computing Intents.
16 Services and Broadcast Receivers CSNB544 Mobile Application Development Thanks to Utexas Austin.
CS378 - Mobile Computing Persistence. Saving State We have already seen saving app state into a Bundle on orientation changes or when an app is killed.
SpotOn Game App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
CS378 - Mobile Computing Intents. Allow us to use applications and components that are part of Android System – start activities – start services – deliver.
Android Boot Camp for Developers Using Java, 3E
Audio Yu Feng CGDD Review 1. Set up 2. IOS sound – Core Audio – Short Sound – Long Sound – Control Sound – Background Sound 3.Cocos2d sound.
CS378 - Mobile Computing Persistence. Saving State We have already seen saving app state into a Bundle on orientation changes or when an app is killed.
Multimedia Capture & storage. Introduction A rich set of API for recording of audio & video. A developer has two choices  launch the built-in app using.
CS378 - Mobile Computing Audio.
Android. What is Android? A mobile device operating system. Seen primary in tablets and Cellphones. Based on a Linux kernel. Applications are Java Based.
Quick Record (Simple Song) 1. Press the Record Button 2. Press the (F2) Soft Button to select Quick Record 3.Press the Play Button to start the recording.
Multimedia. Audio,vedio and Images End user typically refer to vedio/audio using the respective file format MP4 or AVI(audio vedio interleave) Developer.
Editing Digital AudioLab#7 Audacity is a free, easy-to-use and an open source platform audio editor and recorder for Windows, Mac OS, Linux and other operating.
5 Free Online Video Downloader for Android Google Android is the most popular phone system on the world, and the Android phone screen is becoming bigger.
Lecture 7: Media Player Topics: Media Player, Async prepare Date: Mar 3, 2016.
CS371m - Mobile Computing Audio. Audio on Device Devices have multiple audio streams: – music, alarms, notifications, incoming call ringer, in call volume,
CS371m - Mobile Computing Intents 1. Allow us to use applications and components that are already part of Android System – start activities – start services.
Android Application -Architecture.
Video API and Coding Graduate Seminar Dr. Jinan Fiaidhi
Mobile Applications (Android Programming)
Android Application Audio 1.
Multimedia.
Android Application Data Storage 1.
CS371m - Mobile Computing Services and Broadcast Receivers
Lecture 7: Service Topics: Services, Playing Media.
Instructor: Mazhar Hussain
Android Boot Camp for Developers Using Java, 3E
Recording with the Book port Plus
Activities and Intents
Anatomy of an Android App and the App Lifecycle
Lecture 7: Media Player Topics: Media Player, Async prepare
Creation of an Android App By Keith Lynn
The Android Activity Lifecycle
CA16R405 - Mobile Application Development (Theory)
CS5103 Software Engineering
Anatomy of an Android App and the App Lifecycle
Cannon Game App Android How to Program
Android Topics Android Activity Lifecycle and Experiment Toast
CS371m - Mobile Computing Gestures.
Android Topics Custom ArrayAdapters Creating an Event Listener
Network Controllable MP3 Player
Lecture 7: Service Topics: Services, Broadcast Receiver, Playing Media.
Mobile Programming Dr. Mohsin Ali Memon.
Android Development Tools
Presentation transcript:

Audio and Haptic Feedback CS371m - Mobile Computing Audio and Haptic Feedback

Clicker On the whole, do you like apps to provide audio and / or haptic feedback or not? No Yes

Audio on Device Devices have multiple audio streams: music, alarms, notifications, incoming call ringer, in call volume, system sounds, DTMF tones (dual tone multi frequency, the "traditional" phone sounds and tones) Most of the streams are restricted to system events, so we almost always use STREAM_MUSIC via a MediaPlayer or SoundPool

media player

Android Audio Using the Android MediaPlayer class Common Audio Formats supported: MP3, MIDI (.mid and others), Vorbis (.ogg), WAVE (.wav) and others Sources of audio local resources (part of app) internal URIs (Content Provider for other audio available) External URLs (streaming)

Audio Resources res/raw directory assets/ directory reference as file://andorid_asset in a URI can share with other apps via URI Store media in application local directory, pull from network / web and store locally Store and use media on SD card Stream via the Internet

MediaPlayer Playback control of MediaPlayer managed as a state machine Idle Initialized Preparing Prepared Started Paused Playback Complete Stopped End Invalid state transitions result in errors

MediaPlayer State Diagram Single arrows are synchronous transitions Double arrows are asynchronous transitions

Simple Sound Demo App audio files local to app placed in res/raw CAUTION large sound files difficult to install on emulator: http://tinyurl.com/3pwljfj better success with dev phones / actual devices

Using MediaPlayer MediaPlayer.create() method used for raw resources MediaPlayer.create() method for URIs various MediaPlayer.setDataSource() methods if not a raw resource and not a URI

Playing Local Audio To play audio local to the app use the MediaPlayer.create convenience method when complete MediaPlayer in the prepared state start MediaPlayer approach: build listeners for each button to call the playSound method with appropriate song id when clicked

Simple Approach button ids ids for sound files

playSound method initial version useful for short sounds downsides: plays to completion multiple sounds play at same time (desirable in some cases) audio continues to play when app paused

Changing Behavior Add instance variable for MediaPlayer If playing stop and release before creating new Player

Cleaning Up Initial version did not end well Audio continued to play if back button pressed and even if home button pressed! Activity Life Cycle in onPause for app we should stop MediaPlayer and release

stopPlayer method Connect app stop button to stopPlayer could use XML onClick and add View parameter or set up listener ourselves in buildListeners method

onPause onPause() should call the stopPlayer method what happens if activity resumed?

Saving State Resume music where we left off if paused or activity destroyed due to orientation change

Saving MediaPlayer State Not a lot of data so used the SharedPreferences

Restarting Audio In onResume check if audio was interrupted recreate player with same id and move to correct position Can write data to shared preferences or bundle (onSaveInstanceState) and pull out in onResume

audio sources

Playing Audio from Phone If audio is on device / system, but not local to app use a URI Obtain URIs of Music via a Content Resolver Example of simply listing URIs to the logcat

Retrieving Music URIs Using a Content Resolver

MediaPlayer and System Audio After URI retrieved can play audio with MediaPlayer this approach requires calling MediaPlayer prepare yourself Or could use MediaPlayer create method that takes a URI

Playing Audio Via Local URI id obtained via approach from showContent method

Other Audio Other audio for ringtones, notifications, and alarms can be accessed via a RingtoneManager Obtain URIs and play with media player from DDMS:

Listing Other Audio

Playing Other Audio Once the URI is obtained, playing other audio is same as playing song

Playing Audio from Remote URL Straightforward given the URL

Completion of Audio If action required when audio done playing implement the MediaPlayer.onCompletionListener interface could make activity the listener

Looping to loop sound (play over and over) simply set the isLooping method of the MediaPlayer to true

sound pool

SoundPool Another Android class Used in tutorials

Using SoundPool Great for applications with a number of short sound samples maxStreams parameter sets maximum number of sounds that can be played at once via this SoundPool If max is exceeded stream with lowest priority stopped and then by age (oldest) with lowest priority

SoundPool play

Using SoundPool Looping of sounds: frequency (speed) can be changed 0 no looping -1 loop forever >0, play that many times frequency (speed) can be changed range from 0.5 to 2.0 0.5 twice as long to play 2.0 half as long to play

SoundPool.Builder Added in API level 21, Android 5.0 Lollipop static methods to set audio attributes set max number of streams build and return a SoundPool object given the current audio attributes and number of streams Audio Attributes include why, what and how for sound USAGE_GAME, CONTENT_TYPE_SONIFICATION, various flags

Other Sources of Sound AudioTrack http://developer.android.com/reference/android/media/AudioTrack.html low level API for handling audio streams in formats MediaPlayer cannot handle ToneGenerator http://developer.android.com/reference/android/media/ToneGenerator.html Traditional phone tones Dual-Tone Multi-Frequency (DTMF) Just to make sounds, not send tones over phone network

ToneGenerator

haptic feedback

Haptic Feedback haptic: "of or relating to the sense of touch" Easy to add this kind of feedback to an app can enable haptic feedback for any view

Haptic Feedback on a View Methods from View class

HapticFeedbackConstants Class

More Complex Feedback Also possible to create more complex haptic feedback for apps: Request permission Get the Vibrator object from the system call vibrate method

Haptic Feedback Request Permission Get Vibrator

Haptic Feedback Create feedback

Vibrator Methods

recording audio

Recording Audio - MediaRecorder create MediaRecorder object set audio source set audio format set file format for audio set file name to record to prepare MediaRecorder for recording start recording stop and release MediaRecorder

Record Audio Simple View with buttons to start and stop recording alternatively could change text on record audio button single button or toggle switch

Record Audio

Stop Recording a few seconds of audio results in a file size of ~ 10 kb with default settings PERMISSIONS! -- must request RECORD_AUDIO and WRITE_EXTERNAL_STORAGE permissions in manifest file

speech recognition

Speech Recognition android.speech package Simplest example - start an Intent for a result RecognizerIntent.ACTION_RECOGNIZE_SPEECH uses network true on the dev phones doesn't work on emulator

Speech Recognition

Starting Intent

Responding to Result Note: list of results, ordered by confidence

Results