11

アプリケーションで短いサウンドを再生する必要があります。次のコードを書きましたが、Samsungの電話に音が出ず、奇妙な振動が発生しました。しかし同時に、このコードは私のAndroidシミュレーターでうまく機能します。私のコードは次のとおりです。

package com.samplers;

import android.app.Activity;
import android.media.SoundPool;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class FixVibroActivity extends Activity {
    /** Called when the activity is first created. */

    private Button white;
    private SoundPool spool;
    private int soundID;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
        spool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
        soundID = spool.load(this, R.raw.error, 1);

        white = (Button)findViewById(R.id.whiteBtn);
        white.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Sound();
            }
        });
    }

    public void Sound(){
        AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
        float volume = (float) audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        spool.play(soundID, volume, volume, 1, 0, 1f);
    };
}

この問題を解決するのを手伝ってください!前もって感謝します!:)

4

1 に答える 1

7

ボリュームコントロールまたはサウンドファイルの正常な再生に問題がある可能性があります。Sound()機能をこれに変更すると、どうなりますか?お使いの携帯電話がR.raw.errorファイル形式を正しく処理していないが、エミュレータが正しく処理している場合、それは非常に奇妙なことです。

public void Sound(){
        AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
        float volume = (float) audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        android.util.Log.v("SOUND","["+volume+"]["+spool.play(soundID, volume, volume, 1, 0, 1f)+"]");
    };
于 2011-06-18T15:58:17.487 に答える