控制的MediaPlayer量MediaPlayer

由网友(风与尘的誓约)分享简介:我在播放音频(旁白)的有声读物。音频文件是.OGG格式,10和15秒长的每个。I'm playing audio (narration) in an audiobook. The audio files are in .ogg format, between 10 and 15 seconds long each....

我在播放音频(旁白)的有声读物。音频文件是.OGG格式,10和15秒长的每个。

I'm playing audio (narration) in an audiobook. The audio files are in .ogg format, between 10 and 15 seconds long each.

编辑补充:我使用的是Android 2.2系统,API 8,和我有这在我的清单:

Edit to add: I'm using Android 2.2, API 8, and I have this in my Manifest:

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

我有setVolumeControlStream(AudioManager.STREAM_MUSIC);在我的onCreate()方法。

I've got setVolumeControlStream(AudioManager.STREAM_MUSIC); in my onCreate() method.

我的声音正在通过code类似这样的发挥:

My sounds are being played via code similar to this:

mp = MediaPlayer.create(mContext, resource);
mp.setOnCompletionListener(this);
mp.seekTo(0);
mp.setLooping(looping);
if(isSoundEnabled())
{
    mp.setVolume(1, 1);
}
else
{
    // I still need sounds to call their onComplete listeners to drive action
    mp.setVolume(0,0);
}
nowPlaying = true;
mp.start();

但是,尽管有更多的保证(33和计数!),一个只需要setVolumeControlStream(AudioManager.STREAM_MUSIC);中的onCreate(),我的声音不中更改卷I $我的设备(摩托罗拉Xoom)页上$ PSS音量键。

But, despite more assurances (33 and counting!) that one simply needs setVolumeControlStream(AudioManager.STREAM_MUSIC); in onCreate(), my sounds don't change in volume when I press the volume keys on my device (Motorola Xoom).

要验证我的音量键是干什么的的东西的,我推翻的onkeydown

To verify my volume keys were doing something, I overrode onKeyDown:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean result = true;
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP)
    {
        DebugLog.d(TAG, "volume up");
    }
    else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)
    {
        DebugLog.d(TAG, "volume down");
    }
}

和通过LogCat中,我是pressing正确的音量键确认:

and confirmed via LogCat that I'm pressing the correct volume keys:

07-19 12:16:31.440: DEBUG/BookReader(17830): volume down; thread 1
07-19 12:16:31.710: DEBUG/BookReader(17830): volume down; thread 1
07-19 12:16:31.980: DEBUG/BookReader(17830): volume down; thread 1
07-19 12:16:32.440: DEBUG/BookReader(17830): volume up; thread 1
07-19 12:16:32.820: DEBUG/BookReader(17830): volume up; thread 1

虽然下面的链接是关于的Soundpool ,我应该计算流量而是采用 mp.setVolume(1,1); 在我的第一个code以上样品

Though the following link is about SoundPool, should I be calculating stream volume instead of using mp.setVolume(1, 1); in my first code sample above?

推荐答案

检查以确保你的onkeydown每次调用时不返回true。如果是这样的话,那么你告诉机器人,你将处理所有的onkeydown事件,因此Android可能会被忽略的音量键。

Check to make sure you're not returning true every time onKeyDown is called. If that's the case then you're telling android that you'll handle all onKeyDown events, so android might be ignoring the volume key.

阅读全文

相关推荐

最新文章