如何获得MediaPlayer中的当前音量/振幅? [英] How do I get the current volume/amplitude in a MediaPlayer?

查看:418
本文介绍了如何获得MediaPlayer中的当前音量/振幅?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,该应用程序既可以录制音频文件,又可以选择在录制后播放该文件. UI具有一个EQ组件,该组件相对于录制的当前幅度进行动画处理.我已经通过MediaRecorder.getMaxAmplitude()方法使动画工作了,但是找不到任何方法使用MediaPlayer来做到这一点.我知道这是有可能的,因为默认情况下有音乐可视化动态壁纸可以执行此功能,但是在通过AOSP进行梳理时,我看不到它正在拉动该信息的任何方式.有人知道如何使这项工作吗?

I'm working on an app that will both record an audio file, and then have the option to play back that file once it's been recorded. The UI has an EQ component that animates relative to the current amplitude of the recording. I've got the animation working via the MediaRecorder.getMaxAmplitude() method, but can't find any means to do this with MediaPlayer. I know it must be possible since there are music visualization Live Wallpapers by default that perform this functionality but I can't see any way that it's pulling that information when combing through AOSP. Does anybody know how to make this work?

推荐答案

我认为您必须使用音频管理器.如API所述,它可用于音量控制:

I think you have to use AudioManager. As the API states it can be used for volume control:

AudioManager提供对音量的访问 和铃声模式控制.

AudioManager provides access to volume and ringer mode control.

使用 Context.getSystemService(Context.AUDIO_SERVICE) 获取此类的实例.

Use Context.getSystemService(Context.AUDIO_SERVICE) to get an instance of this class.

然后我认为此方法将有用.

这篇关于如何获得MediaPlayer中的当前音量/振幅?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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