帮助/对 Android 版 MediaPlayer 感到困惑?
我一直在尝试为 Android 编写这个音板,但当我使用后退键退出程序以及单击另一个声音时,我对如何停止播放声音感到困惑。我查遍了所有地方,甚至在 Android 开发者网站上,我仍然对该怎么做感到困惑。如果有人可以帮助我,我将不胜感激。我的 MediaPlayer 代码我将发布,但如果实际需要音板代码,我也很乐意发布。
package com.cs.finalfantasysoundboard;
import android.content.Context;
import android.media.MediaPlayer;
public class Music
{
public interface OnCompletionListener {
}
private static MediaPlayer mp = null;
/** Stop old song and start new one */
public static void play (Context context, int resource)
{
stop(context);
mp = MediaPlayer.create(context, resource);
mp.stop();
mp.start();
}
/** Stop the music */
public static void stop(Context context)
{
mp.reset();
mp.release();
mp = null;
}
}
I been trying to program this soundboard for android but I'm stuck and confused on how to stop a sound from playing when I exit the program with the back key and also when clicking on another sound. I've looked all over the place and even on the android developer website an I'm still confused on what to do. If someone could please help me out i'll greatly appreciate it. My MediaPlayer code im going to post but if the actually soundboard code is needed i'll be happy to post that also.
package com.cs.finalfantasysoundboard;
import android.content.Context;
import android.media.MediaPlayer;
public class Music
{
public interface OnCompletionListener {
}
private static MediaPlayer mp = null;
/** Stop old song and start new one */
public static void play (Context context, int resource)
{
stop(context);
mp = MediaPlayer.create(context, resource);
mp.stop();
mp.start();
}
/** Stop the music */
public static void stop(Context context)
{
mp.reset();
mp.release();
mp = null;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以为正在播放或停止的声音实现一些标志。以下是如何通过后退键停止声音:
you can implement some flags for sound being played or stopped etc. Here is how you can stop the sound on Back Key: