Stop other sounds/music - java

I'm creating an application/game in java, which contains background music/sound. Everything works as expected. I want to mute/stop if some system sound/media sound/other sound playing.
Any suggestions...??

I would suggest not care about this problem - let the user decide what programs and sounds he plays in the background

Related

Java - Use music playback control buttons

Usually on keyboards there is buttons to stop the current track, go to the next track, or to the previous one. When I'm playing sound on YouTube for example, and press the F10 key, the video stops.
I'm creating a Java/Kotlin music player. What currently happens when I have music playing, and then I click F10, is that the last YouTube video I have in an open tab starts playing, and the music player does not get effected at all.
What I want is: When I click F10 (or the other control keys), I want my music player to get affected by them, not YouTube.
How can I achieve that?
If I understand correctly, you have an application for playing back sound, but when control keys (e.g., F10 in particular) are pressed, your browser is receiving the key, not your application.
If that is the case, the question seems is about how to use the Swing KeyListener. The KeyEvent API shows that the keycode for the key to be VK_F10. Are you having problems with implementing this? Kotlin might have it's own way of doing key listening, though. I did find this SO question on Kotlin KeyListeners.
As far as starting or stopping a sound, that is usually accomplished by wrapping the audio playback class (Clip or SourceDataLine) in a class that can receive and handle commands to start, stop or continue. Are you having problems with implementing this?
The code that links these two functional areas should be loosely coupled. With that, pursing the two matters as two separate questions will be beneficial.
If your issue is a specific OS implementation question, it would be best to clarify that in the question with additional information.

Why does an activity playing a sound disturb the user interface?

I would like to show a notification and play a sound when the user taps onto that notification. It works somehow when I use an activity to play the sound, as I have written in my own answer to this question: How can I create a notification that plays an audio file when being tapped? (in this question and answer there is also the source code showing how I create the notification and how my PlaySoundActivity looks like.
Yet, I have realized, that while the sound is playing, the appearance of my main application changes and it will not be restored without closing the application.
I have created my application from the "Tabbed Activity" project template.
This is how it looks after being started:
And this is how it looks when I have tapped onto the sound notification (the sections are gone):
Can anyone explain why this happens? Is it a wrong approach to play sound using an activity? But it does not work here when I use a service, I hear nothing! How to solve that?
According to the Android developer reference, "almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI with setContentView(View)".
I had not done this. Therefore a new window was displayed, but there was no content.
The better solution for playing a sound is to use a PlaySoundService (service!!!) instead of an activity. It contains almost the same code as an activity would do, but the pending intent is created with PendingIntent.getService(...) instead of PendingIntent.getActivity(...). Using the wrong method does not result in an obvious error message, but the service won't work as expected.

I want to make a program that recognize a button that is in the League of Legends client

I want to make a program that recognize a button that is in the League of Legends client, and when the queue's button shows up the mouse instantly click on it.
Its a sort of a AutoAccept Client...
There is already a program that someone did, but it has so many unnecessary things and it does not work very well....
How do I do to recognize a element inside a program to make my mouse move there when it shows up?
I can try to code this in any language, just gimme a tip pls
You can create a program that takes a screenshot every 100ms, use a recognition algorithm of your choice and then (optionally) performs a mouse click. There are enough libraries that can screenshot for you, you should be able to recognise the button by colour and location and every language should have some method of controlling the mouse.
Sikulix (can be paired with python) is a perfect tool to use for this. It scans over your screen constantly, and if the image in question pops up (the accept button) you can click on it.
You will have to take a screenshot and likely store it as .png so the program knows what it is looking for.
Google Sikulix.

Java Clip Not Rewinding Properly?

I'm not even sure if the problem is that it's not rewinding properly. I have a Sounds enumerator/class which lets me load all sound effects and then play them at will, and in my game, I initialize them and then each time I want to play one, I play it in its own thread so it doesn't freeze the rest of the game.
The problem is that the first time I hold down or click the mouse to shoot (and thus, play the sound), it plays the sound, even repeatedly, as it's supposed to. But after I release the mouse button and try again, the sound no longer plays.
Does anyone know what the cause of this could be? Here are some code snippets showing the Sounds class and the piece of my code where I am playing the sound.
Sounds class: http://pastebin.com/Hqt5dPQ6
Playing the sound: http://pastebin.com/Lex9ZmzJ
I appreciate any help, as I all but dropped this project a couple of months ago because I wasn't making any progress due to this one stupid problem.

Get input from keyboard with Canvas

I want to create an Upwords application for desktop and so I think that the game table should be displayed as canvas. In the beginning of the game I want to ask the user to make some input about the players that will play, but I don't have any ideas. Could you please help me on that?
Also, if there are better implementation ideas than to use canvas, I would be grateful to hear you.
Thanks in advance.
No it's not my first GUI application but I have very little experience.I think it's a good idea to make my own class but I was't sure because I want to use GUI builder(deadline issues) and in the past I had some problems on this.I will try it.For the input I thought about JDialog but I have to simulate a mobile environment so the prompt must be shown on the "screen"(the canvas on our case).
You have a pretty broad question, and I'm guessing this is your first (or one of your first) graphical programs in java. Instead of using AWT components (like Canvas), I would strongly, strongly recommend using Swing, or really, any other graphical library. I would start by looking at the documentation for javax.swing.JFrame. You will probably end up creating a custom component (extending JComponent?) and overriding its paintComponent() method to provide the custom graphics of your 'game table'.
As far as user input at the start of your game, you may want to look at a dialog box. Look at the documentation for javax.swing.JOptionPane which can create a wide variety of simple dialog boxes for gathering user input, taking care of the keyboard input automagically.
There are plenty of java Swing 'Hello World' type programs out there that can help show you how to create a basic Swing app. The Java Tutorials is a good place to start.
Good luck!

Categories

Resources