Raw フォルダーから MP3 曲のリストを表示し、ユーザーがボタンをクリックして曲を再生できるようにするアプリを作成しています。同じように、ユーザーがクリックした曲を着信音として設定できるようにしたいリスト ボタンでは、以下のスクリーン ショットを参照してください。
MP3 曲のリスト:
PlayActivity.java で選択した曲を表示:
プレイアクティビティ:
// Set as Ringtone
btn5.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Uri path = Uri.parse("android.resource://com.applenty/raw/");
RingtoneManager.setActualDefaultRingtoneUri(
getApplicationContext(), RingtoneManager.TYPE_RINGTONE, path);
Log .i("Ringtone", "Ringtone Set to Resource:: "+ path.toString());
RingtoneManager.getRingtone(getApplicationContext(), path).play();
}
});
ログキャット:
07-10 12:06:05.569: D/dalvikvm(958): GC_FOR_ALLOC freed 37K, 7% free 2486K/2648K, paused 130ms, total 147ms
07-10 12:06:05.630: I/dalvikvm-heap(958): Grow heap (frag case) to 3.153MB for 635812-byte allocation
07-10 12:06:05.719: D/dalvikvm(958): GC_FOR_ALLOC freed 1K, 6% free 3105K/3272K, paused 90ms, total 90ms
07-10 12:06:05.869: D/dalvikvm(958): GC_CONCURRENT freed <1K, 5% free 3121K/3272K, paused 4ms+23ms, total 137ms
07-10 12:06:05.939: D/data count(958): 5//
07-10 12:06:05.979: D/data count(958): 5//
07-10 12:06:05.979: D/data count(958): 5//
07-10 12:06:06.189: D/data count(958): 5//
07-10 12:06:06.210: D/data count(958): 5//
07-10 12:06:06.319: D/data count(958): 5//
07-10 12:06:06.350: D/data count(958): 5//
07-10 12:06:06.519: D/data count(958): 5//
07-10 12:06:06.779: I/Choreographer(958): Skipped 163 frames! The application may be doing too much work on its main thread.
07-10 12:06:06.800: D/data count(958): 5//
07-10 12:06:06.800: D/data count(958): 5//
07-10 12:06:06.889: D/data count(958): 5//
07-10 12:06:06.909: D/data count(958): 5//
07-10 12:06:06.929: D/data count(958): 5//
07-10 12:06:06.979: D/gralloc_goldfish(958): Emulator without GPU emulation detected.
07-10 12:06:07.439: D/data count(958): 5//
07-10 12:06:07.449: D/data count(958): 5//
07-10 12:06:07.579: D/data count(958): 5//
07-10 12:06:07.579: D/data count(958): 5//
07-10 12:06:07.689: D/data count(958): 5//
07-10 12:07:59.060: D/InputEventConsistencyVerifier(958): KeyEvent: ACTION_UP but key was not down.
07-10 12:07:59.060: D/InputEventConsistencyVerifier(958): in android.view.ViewRootImpl@40ce0838
07-10 12:07:59.060: D/InputEventConsistencyVerifier(958): 0: sent at 214631000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_MENU, scanCode=229, metaState=0, flags=0x8, repeatCount=0, eventTime=214631, downTime=214548, deviceId=0, source=0x101 }
07-10 12:07:59.939: D/data count(958): 5//
07-10 12:07:59.939: D/data count(958): 5//
07-10 12:08:00.050: D/data count(958): 5//
07-10 12:08:00.060: D/data count(958): 5//
07-10 12:08:00.119: D/data count(958): 5//
07-10 12:08:08.449: D/dalvikvm(958): GC_CONCURRENT freed 36K, 5% free 3573K/3736K, paused 15ms+58ms, total 346ms
07-10 12:08:13.849: I/Choreographer(958): Skipped 120 frames! The application may be doing too much work on its main thread.
07-10 12:08:22.159: I/Ringtone(958): Ringtone Set to Resource:: android.resource://com.applenty/raw/
07-10 12:08:22.190: D/MediaPlayer(958): Couldn't open file on client side, trying server side
07-10 12:08:22.210: E/MediaPlayer(958): error (1, -2147483648)
07-10 12:08:22.219: D/Ringtone(958): Problem opening; delegating to remote player
07-10 12:08:55.779: I/Ringtone(958): Ringtone Set to Resource:: android.resource://com.applenty/raw/
07-10 12:08:55.779: D/MediaPlayer(958): Couldn't open file on client side, trying server side
07-10 12:08:55.799: E/MediaPlayer(958): error (1, -2147483648)
07-10 12:08:55.799: D/Ringtone(958): Problem opening; delegating to remote player
07-10 12:08:57.089: I/Ringtone(958): Ringtone Set to Resource:: android.resource://com.applenty/raw/
07-10 12:08:57.100: D/MediaPlayer(958): Couldn't open file on client side, trying server side
07-10 12:08:57.109: E/MediaPlayer(958): error (1, -2147483648)
07-10 12:08:57.119: D/Ringtone(958): Problem opening; delegating to remote player
07-10 12:09:02.779: I/Ringtone(958): Ringtone Set to Resource:: android.resource://com.applenty/raw/
07-10 12:09:02.789: D/MediaPlayer(958): Couldn't open file on client side, trying server side
07-10 12:09:02.799: E/MediaPlayer(958): error (1, -2147483648)
07-10 12:09:02.809: D/Ringtone(958): Problem opening; delegating to remote player
07-10 12:09:07.239: I/Ringtone(958): Ringtone Set to Resource:: android.resource://com.applenty/raw/
07-10 12:09:07.249: D/MediaPlayer(958): Couldn't open file on client side, trying server side
07-10 12:09:07.269: E/MediaPlayer(958): error (1, -2147483648)
07-10 12:09:07.269: D/Ringtone(958): Problem opening; delegating to remote player
07-10 12:09:08.589: I/Ringtone(958): Ringtone Set to Resource:: android.resource://com.applenty/raw/
07-10 12:09:08.589: D/MediaPlayer(958): Couldn't open file on client side, trying server side