Transcript Slide 1
Media API
Web Science APT
2007/2008
John Meilak
Reuben Sant
Jason Farrugia
Introduction
• Users demand rich multimedia
capabilities
Media API
• Mobile hardware developed
significantly
• Mobile devices are not simply used
for voice calls and text messaging
Media Capabilities
• Play, stream and record
media resources
• Audio
• Video
• Face Detection
• Used to adjust camera
settings on face
Media API
android.media Package
• Classes
• MediaPlayer
• MediaRecorder
• FaceDetector
• AudioSystem
• Interfaces
• MediaPlayer.OnBufferingUpdateListener
• MediaPlayer.OnCompletionListener
• MediaPlayer.OnErrorListener
• MediaPlayer.OnPreparedListener
Media API
MediaPlayer Example
• Local Resource
MediaPlayer mp = MediaPlayer.create
(context, R.raw.sound_1);
Media API
• Stream
mp.setDataSource(path);
• Video
mp.setDisplay(mPreview.getHolder().getSurface());
• An android.View.Surface is needed to display the video in it.
• mPreview is of type android.view.SurfaceView which is defined
in the xml layout file.
• Playback
mp.prepare();
mp.start();
MediaRecorder Example
MediaRecorder rec = new MediaRecorder();
Media API
rec.setVideoSource(MediaRecorder.VideoSource.CAMERA);
rec.setAudioSource(MediaRecorder.AudioSource.MIC);
rec.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
rec.setVideoSize(400, 300);
rec.setVideoFrameRate(24);
rec.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
rec.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
rec.setOutputFile(path);
rec.prepare();
rec.start();
Supported Media Codecs
• Audio
Media API
– MP3
compression scheme used to transfer audio files via internet
and store in portable media players
– AAC
advanced audio coding, similar to mp3, used by iTunes
– Ogg Vorbis
a free and open source audio codec
– MIDI
used to describe a piece of music in enough detail to be
able to reproduce it accurately
– iMelody
ringtone format
– XMF
extensible music format, used to keep file sizes as small as
possible. used for polyphonic ringtones
– RTTL/RTX
ringtones format
Supported Media Codecs
• Video
Media API
– MPEG-4
compression algorithm for graphics, audio and video
– H.264
simple standard providing good video quality at lower bit
rates
– 3GP
simplified version of mpeg used to accommodate limited
bandwidth of mobile phones
References
• http://code.google.com/android
Media API
• http://www.helloandroid.com
• http://davanum.wordpress.com/2007/12/29/android
-videomusic-player-sample-from-local-disk-aswell-as-remote-urls/
Media API