Java Swing: focus JWebBrowser and press space when button is pressed - java

I have embedded a youtube video as shown here. I have several videos and when one finishes the next one starts automatically. I achieved this by looking up the video duration and starting a TimerTask.
Now there is one problem left: If the user pauses the youtube video, the timer continues and the next video starts after some time.
I thought of this solution but could not make it happen: Implement a JButton, that stops the timer, changes the focus to the youtube video and presses the space button. That should stop the video.
I played with the JWebBrowser.grabFocus() and alike but I was not succesful.
Any help would be appreciated.

Related

In Viewpager2, how to play only one video at a time?

I am creating a project like youtube shorts.
where i have implemented Viewpager2(modal contains only videoview) with RecyclerviewAdapter, everything is ok, but problem is when we swiping both video playing at same time, and some stuck in intial point of scrolling.
So, 1. how to play one video at a time only when screen is fully visible, and second video which coming by scrolling remain pauses or black screen until screen is fully visible?
for smoothness i tried setoffpagelimit method, it plays multiple audio without any scrolling, i think with the solution of first question 2nf question also will solved.

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.

LibGdx resume delay

The problem is when my game is hidden, there is a delay when it's resumed. Each time game is resumed it takes longer. This happens on any screen set including splash screen where assets are being loaded. There is no difference in delay when game is resumed to game screen or splash screen, or menu screen. That means there is no problem with a lot of assets being loaded. I tested other game called "Cut the Rope 2" and there is no such delay, game resumes immediately.
I would like to add, that when I launch application first time, there is no such delay it jumps straight away to splash screen. Also when I press back button, it restarts the whole application and there is no delay also. That means that there is only a delay when application is resumed and there is no delay at all when application is launched first time or restarted.
UPDATE:
My problem is exactly like the one posted in the link below. Problem wasn't solved there. http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=11433&p=51515&hilit=resume+slow#p51515
So the problem is that this is called when my game resumes:
assetManager.finishLoading();
I didn't put that code in resume(). From the link above, I read that it's called automatically. When you press "Back Button" on tablet and then you resume the game, it takes time to launch application. If you press "Lock Button" and then you resume the game it launches game immediately but it freezes. So there are two different behaviors according to the button which was pressed. I would prefer to launch game immediately and not freeze but play my loading screen. Is there any way to do this?
The solution to this problem is to call
Texture.setAssetManager(manager);
In this way AssetManager.finishLoading() will not be called automatically when game is resumed. Therefore it will not reload any assets. AssetManager.update has to be called manually.

Android: Unexpectedly Quit When Trying to Switch Activity

I'm new to posting, but have been using the site for help for a while now. So thanks for that!
I'm working on a new app, got everything running well. It's a kids' soundboard. 2 pages of imagebuttons in a relative layout, with onclick listeners which triggers SoundPool.
My question is this:
in testing I've discovered if you're finger is anywhere on the screen where a button is not (say pressing on the background) and then you try to touch a button (multitouch) ... the button press doesn't register. Any way to fix this?
Thanks!
You have to cover additional event types for multi-touch, if you are not covering below Actions, you are not covering multi-touch
MotionEvent.ACTION_POINTER_DOWN: This event happens for any additional finger that
touches the screen after the first finger touches
MotionEvent.ACTION_POINTER_UP:This gets
fired when a finger is lifted up from the screen and more than one finger is touching
the screen.
The explanation is quite tedious. I suggest you to google multi-touch for android. One helpful link is: http://android-developers.blogspot.in/2010/06/making-sense-of-multitouch.html

Android Media Player Threading/Concurrency

I am using the default Android Media Player in an Activity, trying to play back a couple of video files. However I have a problem with programming what I want. The desired program outcome would be the following:
A video file is played back
After that, a dialog is shown, asking the user something
A pause of 5 seconds occurs
The next video is shown
and so forth
How am I to program this? Currently, I use a paradigm like the following:
I have a method that sets up the player for theĀ a file, e.g. playVideo(int) So I pass it the first file.
When the player is prepared, it will be started in onPrepared(MediaPlayer).
When the video is finished, the onCompletion(MediaPlayer) listener of the media player shows the dialog to the user by calling showDialog().
The user accepts the dialog. Before calling dismiss() on the dialog, the player object is started for the next file by calling playVideo(int).
This works, but it feels a bit quirky and not clean. And it's of course very procedural. The problems are:
that I can't figure out how to insert a pause after the dialog is dismissed.
that I maybe want to change the presentation order of dialogs and videos and this ain't too easy now
Has anyone got an idea?
For the pause, you could use the AlarmManager to schedule an alarm five seconds from now. It will launch an intent, and that intent could call playVideo(int).

Categories

Resources