Multi
Multi
Department of MCA
MULTIMEDIA
MPGE-4 container
Built-in app of Android is available to playback the media, but to get more flexibility
and control on playback, in-app mechanism comes handy
in-app mechanism is implemented using MediaPlayer API
use an implicit Intent to start the intended music player app
The setDataAndType() method is used to set the data source and the type of audio
Intent i = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse(“http://www.mobmusicstore.com/music.mp3”); Playing audio file
i.setDataAndType(uri,“audio/*”);
startActivity(i);
Intent i = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse (“http://www.mobmusicstore.com/video.mp4”);
Playing video file i.setDataAndType(uri,“video/*”);
startActivity(i);
idle state is the first state , player object gets into, as soon as it is created
initialized state is to set the data source – a file path or an HTTP URL of the
media stream. setDataSource() method is used to achieve this
media stream needs to be fetched and decoded so that it can be prepared
for playback by using prepareAsync() during prepared state
Once it is prepared, can be started using start(), followed by play() to
playback the media stream
The media stream can now be paused or stopped by calling pause() or stop()
call release(), once the MediaPlayer object is not required anymore, which
takes it to the end state
An invalid method call from any state may result in errors and exceptions
2-Dec-23 SPRUCING UP MOBILE APPS / 19CA701-Mobile Application Development/Haripriya R/MCA/SNSCT 7
In-app Mechanism
<uses-permission android:name=“android.permission.INTERNET”/>
<uses-permission android:name=“android.permission.WAKE_LOCK”/>
MediaRecorder API
http://www.dre.vanderbilt.edu/~schmidt/android/android-
4.0/out/target/ common/docs/doc-comment-
check/guide/topics/graphics/2d-graphics.html
https://developer.android.com/guide/topics/graphics/drawabl
e-animation