更新:音板应用程序源代码
好的,我已经开始工作了。这将根据上下文菜单将文件保存为铃声、通知或闹钟。 (由于节省空间,仅显示铃声功能)
需要帮助:
由于某种原因,一段时间后没有声音播放。(大约按 20 次左右,直到您退出应用程序并再次启动它才会再次播放)我也有人告诉“/sdcard/media/etc”不是“正确的方法”。
如果有人对如何 1.
按下主页按钮、收到文本或按下后退按钮退出应用程序等时释放/暂停/停止播放声音
有任何建议,以及
2.正确的方法获取SD卡。我会很感激。
MediaPlayer mp1;
MediaPlayer mp2;
MediaPlayer mp3;
MediaPlayer mp4;
MediaPlayer mp5;
protected void onDestroy() {
super.onDestroy();
if(mp1 != null){
mp1.release();
}
if(mp2 != null){
mp2.release();
}
if(mp3 != null){
mp3.release();
}
if(mp4 != null){
mp4.release();
}
if(mp5 != null){
mp5.release();
}
}
protected void onPause() {
super.onPause();
if(mp1 != null){
mp1.stop();
}
if(mp2 != null){
mp2.stop();
}
if(mp3 != null){
mp3.stop();
}
if(mp4 != null){
mp4.stop();
}
if(mp5 != null){
mp5.stop();
}
}
}
protected void onResume() {
super.onResume();
}
OK I got it to work. This will save the file as a ringtone, notification, or alarm based on the context menu. (Only ringtone function is shown due to space conservation)
Need help with:
For some reason no sound plays after awhile.(about 20 or so presses and won't play again until you back out of the app and launch it again) Also I've been told "/sdcard/media/etc" isn't "the correct way" to do it.
If anyone has any suggestions on how to
1.release/pause/stop the sound from playing when the home button is pressed, a text is recieved, or the back button is pressed to exit the app, etc
and
2.the correct way to get the sdcard. I'd appreciate it.
MediaPlayer mp1;
MediaPlayer mp2;
MediaPlayer mp3;
MediaPlayer mp4;
MediaPlayer mp5;
protected void onDestroy() {
super.onDestroy();
if(mp1 != null){
mp1.release();
}
if(mp2 != null){
mp2.release();
}
if(mp3 != null){
mp3.release();
}
if(mp4 != null){
mp4.release();
}
if(mp5 != null){
mp5.release();
}
}
protected void onPause() {
super.onPause();
if(mp1 != null){
mp1.stop();
}
if(mp2 != null){
mp2.stop();
}
if(mp3 != null){
mp3.stop();
}
if(mp4 != null){
mp4.stop();
}
if(mp5 != null){
mp5.stop();
}
}
}
protected void onResume() {
super.onResume();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Q1 的答案:向您的 Activity 添加一个
onPause
方法并调用 MediaPlayer 的stop()
方法。您还应该添加一个onDestroy
方法并调用release
来释放媒体播放器使用的资源。Q2 的答案:看看这篇文章。有关更多详细信息,请阅读有关数据存储
Answer to Q1: Add a
onPause
method to your activity and call MediaPlayer'sstop()
method. You should also add aonDestroy
method and callrelease
to free the resources used by the mediaplayer.Answer to Q2: Take a look at this post. For more details read the Android Developers info on Data Storage