如何在按下按钮时持续循环播放声音并在释放时停止?
我确信我的问题非常简单。只是我不太确定如何有效地描述我想要实现的目标。
无论如何,我有一个简单的按钮,我知道如何“链接”原始声音文件以手动播放它。但我想做的可能是将 3 秒的声音链接到按钮,并在用户按住按钮时让它循环播放,然后在松开按钮时停止播放。任何人都可以分享任何示例链接,那就太好了!谢谢你!
编辑: 谢谢欧伦德上尉!
谢谢,这绝对有帮助,并且成功了,但是我遇到了 1 个小问题,也许你可以帮助我,我正在使用“自定义按钮”,如 http://developer.android.com/resources/tutorials/views/hello-formstuff.html
在我之前它工作得很好添加了“onTouch Listener。按钮现在不使用它的 android:state_pressed 项目,它只显示普通项目,而不是按下的项目。至少它现在播放声音。但是,有什么想法吗?
My question is a very simple one i'm sure. It's just I'm not quite sure how to effectively describe what i'm trying to achieve.
Anyway to the point, I have a simple button, I know how to "link" a raw sound file to hand make it play. BUT what i want to do is maybe link a 3 second sound to the button and just have it loop while the user holds the button, and then stops playing when the button is let go. Anyone have any example links they could share that would be great! Thank you!
edit:
Thank you Cpt.Ohlund!
Thanks that was definately helpful and did the trick, however i ran into 1 more small problem maybe you could help me with I'm using a "Custom Button" as seen on http://developer.android.com/resources/tutorials/views/hello-formstuff.html
It worked fine before i added the "onTouch Listener. The Button now doesn't use it's android:state_pressed Item it just displays the normal item but not the pressed item. At least It plays the sound now. But, Any Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用以下内容,只需将 R.raw.hit 更改为您自己的声音文件:
}
You could use the following, just change R.raw.hit to your own soundfile:
}