[Source] MP3 ÆÄÀÏ ½ÇÇàÇϱâ |
|
|
|
8³â Àü
|
ÂüÁ¶: http://developer.android.com/guide/topics/media/index.html
// AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.anddev.android.musicplayer">
<application android:icon="@drawable/icon">
<activity class=".MusicPlayer" android:label="@string/app_name">
<intent-filter>
<action android:value="android.intent.action.MAIN" />
<category android:value="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
// MusicPlayer.java
import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MusicPlayer extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
// Find the Button from the xml-file.
Button cmd_play = (Button)this.findViewById(R.id.cmd_play);
cmd_play.setOnClickListener(new OnClickListener(){
//@Override
public void onClick(View arg0) {
// res/raw Æú´õ³»¿¡ sound_file ÆÄÀÏÀ» Ãß°¡ÇسõÀ½.
MediaPlayer mp = MediaPlayer.create(MusicPlayer.this,
R.raw.sound_file);
mp.prepare();
mp.start();
// i.e. react on the end of the music-file:
mp.setOnCompletionListener(new OnCompletionListener(){
//@Override
public void onCompletion(MediaPlayer arg0) {
// File has ended !!! Wink
}
});
}
});
}
}
|
|
̵̧ : 248 |
̵̧
¸ñ·Ï
|
|