Media On The Android Platform: March 6, 2010 Jason Shah
Media On The Android Platform: March 6, 2010 Jason Shah
Media On The Android Platform: March 6, 2010 Jason Shah
March 6, 2010
Jason Shah
jshah@jsdfllc.com
http://www.jsdfllc.com
Twitter: jasonshah
Agenda
2
Who am I?
• Past:
• Neuros Technology
• Bain & Company
• Trilogy Software
3
Current Android work
Mediafly Mobile
(confidential)
(confidential)
Chicago Transit
Tracker Pro / Lite
US National Debt
(sample app)
4
Target audience
5
Source: Google
Goals for today
• Demonstrate android.media
6
Agenda
7
What Android gives you
Lots of other stuff android.media • Ringtones, audio volume, media scanners, JET
players, audio formats, and more.
Note: Core/G1 indicates whether codec is guaranteed to work across all devices, or specific to G1 device.
Additional codecs may be supported by future devices. 10
Source: http://developer.android.com/guide/appendix/media-formats.html
Agenda
11
MediaPlayer: Introduction
Notes:
• Single arrow = synchronous
• Double arrow = asynchronous
• Error and End states can be
reached from any state in the
diagram
13
MediaPlayer: Create and prepare
Option 1:
MediaPlayer mp =
MediaPlayer.create(context,
uri);
Option 2:
MediaPlayer mp;
mp = new MediaPlayer();
mp.setDataSource(uri);
mp.prepare();
Notes:
• setDataSource(): sets the data
source as URI or file descriptor
• prepare(): Synchronously prepares
data for playback by buffering data.
• Asynchronous version
(prepareAsync) also available.
• Callback OnPreparedListener
called if registered on
14
completion
MediaPlayer: Seek to time
mp.seekTo(time);
Notes:
• seekTo(): seeks to a specific time
in the file in milliseconds.
• Call returns immediately,
but seeking may take several
seconds (especially for
streams).
• Callback
OnSeekCompleteListener
called if registered on
completion
• seekTo on streams is broken in
Android 1.6-2.1! See Android bug
#4124
15
MediaPlayer: Start playback
mp.start();
Notes:
• start(): starts playback.
16
MediaPlayer: demo
17
MediaPlayer: Additional control
• mp.pause();
• Stops playback and keeps
current seek position
• mp.stop();
• Stops playback and loses
current seek position
• mp.seekTo();
• Move playhead to new time,
buffer new content, and start
playing. May take several
seconds, especially if
streaming.
• mp.reset();
• Move player back to Idle
state
• mp.release();
• Move player to End state
• Release all internal
resources held by player
18
Agenda
19
MediaController: Introduction
20
MediaController: Introduction
I’m a
MediaController
21
Image source: http://www.simplehelp.net/2009/07/29/how-to-copy-music-to-your-android-phone-from-windows/
MediaController: Setting it up
24
VideoView: Introduction
• VideoView attaches to a
MediaPlayer to provide default
video rendering capabilities
for video from various sources
• Computes its own
measurement from the video
• Can be used in any layout
manager
• Provides scaling, tinting, etc.
25
Image source: http://www.saturn.dti.ne.jp/~npaka/android/VideoViewEx/VideoViewEx.gif
VideoView: Setting it up
• Demo VideoView
27
Agenda
28
SoundPool: Introduction
• SoundPool:
• Loads samples into memory from resources or files and
decompresses them
• Manages the number of actively playing streams by
assigned priority
• Allows playback rate and pitch changes real-time
29
SoundPool: Gaming Use Case
30
Agenda
31
Trouble ahead!
32
Agenda
33
References
Reference Source
Android 1.5 API http://developer.android.com/sd
k/1.5_r3/index.html
34
Questions?
Thank you!
Jason Shah
jshah@jsdfllc.com
http://www.jsdfllc.com
Twitter: jasonshah
35