0

Requirement: Volume control without UI intervention. The client app getting different videos to play in VideoView and it usages the MediaPlayer class to control the playback of these video files. These video data has a volume level we want the content to play at.

The Audionamanager API "isVolumeFixed()" returing false meaning the device has not implemented a fixed volume policy and we can use Audionamanager APIs to adjust the device volume (although we should not as pointed here https://developer.amazon.com/docs/fire-tv/multimedia-app-requirements.html#requirement-81-do-not-modify-global-device-state). BUT, None of these Audionamanager APIs seems working. Alternatively (and as recomended) I am using the "setVolume()" API to set the volume for the current player instance. But again I could not see any change in the volume level. No effect even when trying to set full volume with "setVolume(1.0f, 1.0f)".

Below is the sample code snippet:

private void updateVolume(MediaPlayer mp, int volume) {
    AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    
    int currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    int streamMaxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    float updatedVolume = (float) (volume * streamMaxVolume) / 100; 
    try {
        if(!audioManager.isVolumeFixed()) {
            if(updatedVolume > streamMaxVolume) {
                audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, streamMaxVolume, 0);   //set max volume.
            } else {
                audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, (int) updatedVolume, 0);   //set custom volume.
            }
        } else {
            mp.setVolume(updatedVolume, updatedVolume); //tried to set volume with this directly with diffrent float levels (0.0f to 1.0s) but none has worked
        }
    } catch (SecurityException e) {
        Log.i(TAG, "updateVolume Security Exception with setStreamVolume() message: " + e.getMessage());
    }
}

I am calling this method within videoview's onPrepared()

Permissions included:

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

On mobile phone this is working fine, but not on Amazon fire tv stick. Surprisingly, the below logs are also apearing from Amazon SDK, even though isVolumeFixed() returing false:

AmazonAudioService   system_server   W  ignore volume adjustment on fixed volume device: 1024
AmazonAudioService   system_server   W  setStreamVolume rejected for com.example.videoviewsample

I found few similar thread like this, but could not get any help out of it. It would be great if you would get any input on this.

Akki
  • 775
  • 8
  • 19

0 Answers0