简体   繁体   English

如何创建淡出按钮

[英]How to create a fade out button

I want to make a button onclick to fade out the music and call the media player to stop? 我想使onclick按钮淡出音乐并呼叫媒体播放器停止播放吗?

I want this to be over 5 sec 我希望这个时间超过5秒

I have tried to make a timer like code, but i dont get how to make it work - can you guys help me? 我试图使计时器像代码一样,但是我不知道如何使其工作-你们可以帮我吗?

float volume = 1;
float speed = 0.05f;

    public void FadeOut(float deltaTime); 
{ 
mpMain.setVolume(1, 1); 
volume -= speed* deltaTime; } 
public void FadeIn(float deltaTime1); 
{ 
mpMain.setVolume(0, 0); 
volume += speed* deltaTime1; } 


}}

The difference between 和...之间的不同

Android: How to create fade-in/fade-out sound effects for any music file that my app plays? Android:如何为我的应用播放的任何音乐文件创建淡入/淡出声音效果?

and the code that you posted, is that you set the volume directly to 1, and ignore the volume variable that you're changing. 您发布的代码是将音量直接设置为1,而忽略要更改的音量变量。 Instead use the volume variable exactly as they do in the solution to the other question. 而是完全按照在其他问题的解决方案中使用的方式使用volume变量。 This also needs to be called several times via a timer. 这也需要通过计时器多次调用。

deltatime should be the amount of time that passed since the last time the method was called. deltatime应该是自上次调用该方法以来经过的时间。 This is to keep the fade consistent if the phone lags or something. 这是为了在电话停滞或发生某些情况时保持淡入淡出的一致性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM