即使在静音模式下如何启用媒体声音 [英] how to enable media sound even in silent mode

查看:210
本文介绍了即使在静音模式下如何启用媒体声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使在静音模式下,我如何开始发出声音?我将音频文件保存在原始文件夹中.我已经编写了一些代码,但是当我转到android的声音设置时,只有铃声和闹钟更改为最大值,但媒体部分没有更改.这是我的代码

how do i start the sound even in silent mode? i got my audio file in my raw folder. i've made some codes but when i go to sound settings of android the ringtone and alarm are the only ones that are changed to maximum but not the media part. here is my code

public void playSound(Context context)
{
    AudioManager audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
    int maxVolumeAlarm = audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM);
    int maxVolumeRing = audioManager.getStreamMaxVolume(AudioManager.STREAM_RING);
    audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
    audioManager.setStreamVolume(AudioManager.STREAM_ALARM, maxVolumeAlarm,AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
    audioManager.setStreamVolume(AudioManager.STREAM_RING, maxVolumeRing,AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);;
    MediaPlayer mMediaPlayer;
    mMediaPlayer = new MediaPlayer();
    mMediaPlayer = MediaPlayer.create(context, R.raw.puff);
    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mMediaPlayer.setLooping(false);
    mMediaPlayer.start();
}

推荐答案

现在可以了,我使用了这段代码

it's okay now, i used this code

AudioManager audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
    int maxVolumeMusic = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
    audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, maxVolumeMusic,AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);

这篇关于即使在静音模式下如何启用媒体声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆