Recap:Android Components Application=Set of Android Components Activity Ul Component typically correspo one screen. BroadcastReceiver Responds to notifications or statu changes.Can wake up your proc Intent Service Faceless task that runs in th background. ContentProvider Enable applications to share
Recap: Android Components Application= Set of Android Components • UI Component typically corresponding to Activity one screen. • Responds to notifications or status changes. Can wake up your process. BroadcastReceiver • Faceless task that runs in the background. Service ContentProvider • Enable applications to share data. Intent
Android Programming Lecture 10 Multimedia
Android Programming Lecture 10 Multimedia
APPLICATIONS Home Contacts Phone Browser APPLICATION FRAMEWORK Activity Window Content View Manager Manager Providers System Package Telephony Resource Location Notification Manager Manager Providers System System ANDROID RUNTIME Surface Media SQLite Manager Framework Core Libraries OpenGLES FreeType WebKit Dalvik Virtual Machine SGL SSL libe LINUX KERNEL Display Camera Flash Memory Binder (IPC) Driver Driver Driver Driver Keypad Driver WiFi Dirver Audio Power Drivers Management 3
3
Operating System Multimedia Framework Audio Video MP3 。H.263 MIDI ·H.264AVC ·PCM/WAVE ·MPEG-4 ·AAC LC etc... etc... Software Hardware Codec The Android multimedia framework includes support for playing variety of common media types,so that you can easily integrate audio,video and images into your applications
4 The Android multimedia framework includes support for playing variety of common media types, so that you can easily integrate audio, video and images into your applications. Audio • MP3 • MIDI • PCM/WAVE • AAC LC • etc… Video • H.263 • H.264 AVC • MPEG-4 • etc…
Media Playback Android multimedia framework includes support for playing variety of common media types,so that you can easily integrate audio,video and images into your applications. You can play audio or video from media files stored in your application's resources (raw TECSUN e360- resources),from standalone files in the file system,or from a data stream arriving over a network connection,all using MediaPlayer class
Media Playback 5 • Android multimedia framework includes support for playing variety of common media types, so that you can easily integrate audio, video and images into your applications. • You can play audio or video from media files stored in your application’s resources (raw resources), from standalone files in the file system, or from a data stream arriving over a network connection, all using MediaPlayer class
Media Playback Guide ● http://developer.android.com/guide/topics/media/mediapl ayer.html
Media Playback Guide • http://developer.android.com/guide/topics/media/mediapl ayer.html 6
Media Player One of the most important components of the media framework is the MediaPlayer class.An object of this class can fetch,decode, and play both audio and video with minimal setup.It supports several different media sources such as: o Local resources o Internal URIs,such as one you might obtain from a Content Resolver o External URIs(streaming) Supported Media Formats are: o RTSP(RTP,SDP) o HTTP/HTTPS progressive streaming TECSUN 口oo口当 10360- o HTTP/HTTPS live streaming o 3GPP o MPEG-4 o MP3
Media Player • One of the most important components of the media framework is the MediaPlayer class. An object of this class can fetch, decode, and play both audio and video with minimal setup. It supports several different media sources such as: o Local resources o Internal URIs, such as one you might obtain from a Content Resolver o External URIs (streaming) • Supported Media Formats are: o RTSP (RTP, SDP) o HTTP/HTTPS progressive streaming o HTTP/HTTPS live streaming o 3GPP o MPEG-4 o MP3 7
Step 1:Create the raw folder in the project and put the media file into the folder Step 2:Configure the media player object ServiceAndMediaPlayer ·售sc to start the media playback com.example.serviceandmediaplayer gen [Generated Java Files] D☐Android4.4w /Create an instance of MediaPlayer and load the music Android Private Libraries MediaPlayermediaPlayerMediaPlayer.create(this, Android Dependencies 凸assets R.raw.music)j bin /Start the media playback D邑bs mediaPlayer.start(); ·是res drawable-hdpi drawable-ldpi drawable-mdpi To replay the media,call reset()and drawable-xhdpi drawable-xxhdpi prepare() raw To pause,call pause() music.mp3 values ·To stop,call stop() values-v11 evalues-v14 AndroidManifest.xml ic_launcher-web.png MediaPlayer class reference: clint.xml http://developer.android.com/reference/android/media/Media proguard-project.txt 目project.properties Player.html
8 // Create an instance of MediaPlayer and load the music MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.music); // Start the media playback mediaPlayer.start(); Step 1: Create the raw folder in the project and put the media file into the folder Step 2: Configure the media player object to start the media playback • To replay the media, call reset() and prepare() • To pause, call pause() • To stop, call stop() MediaPlayer class reference: http://developer.android.com/reference/android/media/Media Player.html
Media Player Whit this example you can play an audio file as a local raw resource from res/raw/directory: MediaPlayer mediaPlayer MediaPlayer.create(context,R.raw.sound_file_1); mediaPlayer.start ()/no need to call prepare;create(does that for you You can also load a local content through an URI Object Uri myUri =..../initialize Uri here MediaPlayer mediaPlayer new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAMMUSIC; mediaPlayer.setDataSource (getApplicationContext(),myUri); mediaPlayer.prepare(); mediaPlayer.start(); You can also play a content from a remote URL via HTTP streaming. String url=“http:/∥..";/∥your URL here MediaPlayer mediaPlayer=new MediaPlayer(); mediaPlayer.setAudioStreamType (AudioManager.STREAMMUSIC); mediaPlayer.setDataSource(url); mediaPlayer.prepare(;/might take long!(for buffering,etc) mediaPlayer.start(); 9
Media Player • Whit this example you can play an audio file as a local raw resource from res/raw/ directory: • You can also load a local content through an URI Object • You can also play a content from a remote URL via HTTP streaming. 9 MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.sound_file_1); mediaPlayer.start(); // no need to call prepare(); create() does that for you String url = "http://........"; // your URL here MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mediaPlayer.setDataSource(url); mediaPlayer.prepare(); // might take long! (for buffering, etc) mediaPlayer.start(); Uri myUri = ....; // initialize Uri here MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mediaPlayer.setDataSource(getApplicationContext(), myUri); mediaPlayer.prepare(); mediaPlayer.start();
Read Media Information void attachAuxEffect(int effectld) Attaches an auxiliary effect to the player. int getCurrentPosition( Gets the current playback position 060- int getDuration Gets the duration of the file. int getVideoHeight0 Returns the height of the video. int getVideoWidth 0 Returns the width of the video. boolean isLooping0 Checks whether the MediaPlayer is looping or non-looping. boolean isPlaying0 Checks whether the MediaPlayer is playing. 10
Read Media Information 10