-1

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
4

3 に答える 3

5

パスが正しいと仮定すると、これは、この投稿から取得した着信音に曲を設定する 1 つの方法です。

File k = new File(path, "mysong.mp3"); // path is a file playing

ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, "My Song title"); //You will have to populate 
values.put(MediaStore.MediaColumns.SIZE, 215454);
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
values.put(MediaStore.Audio.Media.ARTIST, "Band Name"); //You will have to populate this
values.put(MediaStore.Audio.Media.DURATION, 230);
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
values.put(MediaStore.Audio.Media.IS_ALARM, false);
values.put(MediaStore.Audio.Media.IS_MUSIC, false);

//Insert it into the database
Uri uri = MediaStore.Audio.Media.getContentUriForPath(k.getAbsolutePath());
Uri newUri = main.getContentResolver().insert(uri, values);

RingtoneManager.setActualDefaultRingtoneUri(
  myActivity,
  RingtoneManager.TYPE_RINGTONE,
  newUri
);
于 2013-07-11T15:53:34.283 に答える
4

これを試してみてください、それはあなたにとって良いことです

File newSoundFile = new File("pathFile");
        if (DebugUtil.DEBUG) {
            DebugUtil.logError(new Exception(), newSoundFile.getAbsolutePath());
        }
        ContentValues values = new ContentValues();
        values.put(MediaStore.MediaColumns.DATA, newSoundFile.getAbsolutePath());
        values.put(MediaStore.MediaColumns.TITLE, songVO.getTitle());
        values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/*");
        values.put(MediaStore.MediaColumns.SIZE, newSoundFile.length());
        values.put(MediaStore.Audio.Media.ARTIST, R.string.app_name);
        values.put(MediaStore.Audio.Media.DURATION, 230);
        values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
        values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
        values.put(MediaStore.Audio.Media.IS_ALARM, false);
        values.put(MediaStore.Audio.Media.IS_MUSIC, false);

        Uri uri = MediaStore.Audio.Media.getContentUriForPath(newSoundFile.getAbsolutePath());
        context.getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + newSoundFile.getAbsolutePath() + "\"", null);
        Uri newUri = context.getContentResolver().insert(uri, values);

        try {
            RingtoneManager.setActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE, newUri);
            KitKatToast.makeText(context, R.string.msg_setAsRingTuneSuccess, KitKatToast.LENGTH_LONG).show();
        }
        catch (Exception e) {
            if (DebugUtil.DEBUG) {
                DebugUtil.logError(new Exception(), e.toString());
            }
        }
于 2014-01-15T15:33:30.393 に答える
-2

これを試してください:

これはクリックメックです

btn5.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {                               
            MediaPlayer mPlayer = MediaPlayer.create(FakeCallScreen.this, R.raw.mysoundfile);
            mPlayer.start();
        }
});

public void onDestroy() {
    mPlayer.stop();
    super.onDestroy();
}

マニフェスト ファイルにアクセス許可を追加します。

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
于 2013-07-10T12:38:48.800 に答える