我一直致力于播放某些音频的应用程序。我目前正在播放音频作为STREAM_MUSIC类型的流,这工作得很好。我希望能够通过设备上的硬件音量控制来控制音量。当我在应用程序中时,硬件按钮不起任何作用,音量不会改变,并且不会弹出。然后按主页按钮,以便应用程序在后台运行硬件音量按钮。它们只在我的应用程序在后台运行时才起作用。当我的应用程序运行时,硬件音量按钮不起作用
我试图在我的onCreate()
方法中使用代码this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
,这并没有改变应用程序的行为,我仍然面临同样的问题。
我也一直在DROID 2,DROID RAZR,三星Galaxy s3,三星Galaxy s4,联想平板电脑和一个根源DROID 2上进行测试,但它们都表现相同。
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
setVolumeControlStream(audio.STREAM_MUSIC); //this line should set up the hardware
//buttons to control the volume
if (QtApplication.m_delegateObject != null && QtApplication.onCreate != null) {
QtApplication.invokeDelegateMethod(QtApplication.onCreate, savedInstanceState);
return;
}
requestWindowFeature(Window.FEATURE_NO_TITLE);
try {
m_activityInfo = getPackageManager().getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
} catch (NameNotFoundException e) {
e.printStackTrace();
finish();
return;
}
if (null == getLastNonConfigurationInstance()) {
// if splash screen is defined, then show it
if (m_activityInfo.metaData.containsKey("android.app.splash_screen"))
setContentView(m_activityInfo.metaData.getInt("android.app.splash_screen"));
startApp(true);
}
}
我已尝试在我的onCreate()方法中使用setVolumeControlStream(),并且它没有改变任何东西。 – kobihudson
如果您向我们展示您已经编写的代码,我们会很有帮助。 – Dyna
我只是将一些代码添加到原始文章中。 – kobihudson