Android的:如何创建淡入/淡出音效任何音乐文件,我的应用程序的戏剧? [英] Android: How to create fade-in/fade-out sound effects for any music file that my app plays?

查看:706
本文介绍了Android的:如何创建淡入/淡出音效任何音乐文件,我的应用程序的戏剧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的工作就播放音乐文件的应用程序。如果定时器超时我想要的音乐淡出。我怎么做。我使用的MediaPlayer播放音乐和音乐文件present在我的应用程序的原始文件夹。

The application that I am working on plays music files. If a timer expires I want the music to fade out. How do I do that. I am using MediaPlayer to play music and music files are present in raw folder of my application.

推荐答案

做到这一点的方法之一是使用MediaPlayer.setVolume(左,右),并让这些价值递减后,每iteration..here是一个粗略的想法

One way to do it is to use MediaPlayer.setVolume(right, left) and have these values decrement after every iteration..here is a rough idea

float volume = 1;
float speed = 0.05f;

public void FadeOut(float deltaTime)
{
    MediaPlayer.setVolume(volume, volume);
    volume -= speed* deltaTime

}
public void FadeIn(float deltaTime)
{
    MediaPlayer.setVolume(volume, volume);
    volume += speed* deltaTime

}

的淡入或淡出应称为一旦你的这个定时器已经期满,则该方法犯规需要采取deltaTime但其良好的做法,因为它会降低音量在所有设备相同的速率

The FadeIn or FadeOut should be called once this timer of yours has expired, the method doesnt need to take the deltaTime but its good practise as it will lower the volume at the same rate across all devices

这篇关于Android的:如何创建淡入/淡出音效任何音乐文件,我的应用程序的戏剧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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