java - How do I stop my sound/music from playing in another frame? -
i used following code play song it's 11 minutes long how can stop it?
this code in jframe 1. how can make stop in jframe 2?
inputstream test =getclass().getclassloader().getresourceasstream("musics/menu.wav"); audiostream audio = new audiostream(test); audioplayer.player.start(audio); i tried chaning audioplayer.player.start(audio); audioplayer.player.**stop**(audio); no success.
normal java naming conventions variables start lower case letters, audio in audiostream audio = new audiostream(test); may misinterpreted class, not local variable.
i think this link can stop method, if that's code isn't working.
if you're not having trouble stop method nor variable names, suggest use separate class hold audiostream objects , make them static, class in same package can access it.
your class this:
public class audiohelper { static inputstream test = getclass().getclassloader().getresourceasstream("musics/menu.wav"); static audiostream audio = new audiostream(test); public static void play() { audioplayer.player.start(audio); } public static void stop() { audioplayer.player.stop(audio); } } and can access methods this, no matter jframe you're in:
audiohelper.play(); audiohelper.stop();
Comments
Post a Comment