Slick2D Music Trouble - java

I'm new to Slick2D, LWJGL, etc. Anyway I've been trying to make a simple in-game menu when pressing the escape button. Everything works fine, however when I hit the escape button I would like the current music to pause and play a sound when the menu opens. Then for the music to continue when the menu closes. However when I do hit escape it works the sound plays and the music stops, but when I hit escape again the music doesn't resume. Any suggestions?
if(input.isKeyPressed(Input.KEY_ESCAPE)) {
//Toggles Menu Open/Close
inGameMenu = !inGameMenu;
//Toggle Music to shut off
pauseMusic = !pauseMusic;
//Opacity trick
InGameMenu.resetOpacity = !InGameMenu.resetOpacity;
//toggle menu open/close
InGameMenu.closeMenu = !InGameMenu.closeMenu;
if(pauseMusic){
if(Sound.bgMusic.playing()){
Sound.bgMusic.pause();
}
ObjectSounds.menuOpen.play();
} else {
if(ObjectSounds.menuOpen.playing()) {
ObjectSounds.menuOpen.stop();
}
if(!Sound.bgMusic.playing())
Sound.bgMusic.play();
}
System.out.println(pauseMusic);
}

Turns out Music is its own dedicated audio channel, but there is Sound which is another.

Related

Cant disable the microphone on a android phone

I want to create an app that only letting through microphone sound by pressing and holding the headphone pause button.
I am trying the following code to mute the microphone:
AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audioManager.setMicrophoneMute(true);
But when this code is executed the microphone still works, can any one help me to disable the microphone? And also when the app is running in the background, it still needs to disable the microphone.
private void setMicMuted(boolean state){
AudioManager myAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
// get the working mode and keep it
int workingAudioMode = myAudioManager.getMode();
myAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
// change mic state only if needed
if (myAudioManager.isMicrophoneMute() != state) {
myAudioManager.setMicrophoneMute(state);
}
// set back the original working mode
myAudioManager.setMode(workingAudioMode);
}

Changing from a non activity to an activity Android Studio

I'm currently developing a game app for my 2nd year project at uni, but i'm a little stuck on how i can move from a non-activity class to an activity. So my none activity class is a quit screen within the game (yes i know you shouldn't use quit in a game but its one of my requirements), when i click on a button i want it to take me to the activity. (which basically thanks the user for playing and then exits the app) using System.exit(0) is just going back to the last activity visited.
The screen extends my Game Screen Class which is a parent class i created, this is the code for what happens when the user touches the 'yes' button in the quit screen:
#Override
public void update(ElapsedTime elapsedTime) {
Input input = game.getInput();
List<GameTouchEvent> touchEvents = input.getTouchEvents();
if(touchEvents.size() > 0){
GameTouchEvent touchEvent = touchEvents.get(0);
if(yesButtonBound.contains((int) touchEvent.x, (int) touchEvent.y)){
System.exit(0);
}
I'm not looking for specific code answers as this is a project but any advice or hints would be very appreciated thanks!!

Clearing Screen stack and disable back button in Blackberry Application

I have a requirement to restrict the user from pressing back button or disabling the back button in a screen. How should I get the Task done?
And Also on the same screen if user clicks the Ok button all the Screens from Home should get cleared and Home Screen should be displayed.
I got an answer here but it doesn't work. I am testing the app on Simulator 9550. Don't whether it is OS issue.
Thanks.
In order to modify the behaviour when the user presses ESC / back, you simply override the keyChar() method in your Screen subclass(es):
protected boolean keyChar(char c, int status, int time) {
if (c == Characters.ESCAPE) {
// do nothing if ESC was pressed
return true;
} else {
// accept the default behaviour for other keys
return super.keyChar(c, status, time);
}
}
In order to pop (remove) all screens except the app's home screen see this recent answer ... the one you linked to has a bug in it.

I want to run the application in background of mobile without any GUI in mobile using J2ME?

I am developing the network application in which I want to run my J2ME MIDP application in background without any GUI so that is any way to construct the application is such manner.
try this
set your current Display to null. so there will not be any form or alert running on the screen. But however your code will be running in the background.
Display display = Display.getDisplay(this); // here 'this' points to Midlet
display.setCurrent(null);
it easy just have a code of line on any event for example in the click of button
Display.getDisplay (this).setCurrent (null);
and return back the control via
Display.getDisplay (this).setCurrent (mycanvas);
Yes this code works Good,
display = Display.getDisplay(this);
public void startApp()
{
display.setCurrent(form);
}
public void pauseApp()
{
}
public void hide()
{
Display.getDisplay (this).setCurrent (null);
}
This is will work like, make a button can after clicking it call hide Function, or you call this hide function in constructor so it will hide itself when app start, can you keep unHide statement in appStart() so if you Tab the program then it will unHide app again.
NOTE: you said you are working on Network app, but some mobile will turn off the Internet Connection, when the Mobile screen Turn Off. please check this. and If you found any solution It will be Good to share here.

play video using jmf repeat automcatically

hello friends
i dont know more about jmf i play video using java media framework. now
How Can repeat video automatically means video play for ever until usr press stop button
thanks
"Reaching the end of play (signaled by an EndOfMedia event) is dealt with by setting the media's own time to zero (back to the start) and restarting the Player" [Book: (Java™ Media APIs: Cross-Platform Imaging, Media, and Visualization)]
In the code below, the object p is a player.
p.addControllerListener(new ControllerListener() {
public void controllerUpdate(ControllerEvent event) {
if (event instanceof EndOfMediaEvent) {
p.setMediaTime(new Time(0));
System.out.println("End of Media – restarting");
p.start();
}
}
});
After creating the player, you could add a ControllerListener. When the file ends an EndOfMediaEvent is generated. When you get that event, you can use the function setMediaTime(0) to start playing the file from the beginning
With an mp3, I had to call both player.start() and player.setMediaTime(new Time(0.)). Otherwise it would not replay any other way.

Categories