I am trying to play a list of mp3 files in JavaFx and need to pause for few seconds in between each file.This question may be subjective but I am unable to find any technique to get handle of another JavaFx MediaPlayer object at the end of currently playing mediaPlayer, which is being played inside a runnable object.
Any code sample/Algorithm will be a great help.
Create a list of mediaPlayers, iterate through the list and for each mediaPlayer:
Call mediaPlayer.setonEndofMedia.
In your end of media Runnable create a PauseTransition for the duration you want to pause.
Supply a setOnFinished event handler for the pause transition which starts the next MediaPlayer in the list.
Turn #SoulMan's comment into answer:
Thanks I used the following code:
PauseTransition pt = new PauseTransition(Duration.millis(2000));
pt.play();
pt.setOnFinished(
new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
if (mediaPlayer3 != null) {
mediaPlayer3.play();
}
}
});
Related
Currently, in my project, we are using gtkmm pixbuf create_from_file or create_from_date which hangs up whole GUI for 1-2 seconds in case of high-resolution images and in case of loading multiple images for a screen it becomes awfully slow. Is it possible to load images asynchronously in gtkmm for the above two functions? I am able to find methods in gtk for loading images asynchronously but not in gtkmm. An example would be helpful since I am unable to find anything related to it.
if(!imageName.empty())
{
//Load image in pixbuf
picPixBuff = Gdk::Pixbuf::create_from_file(imageName);
picPixBuff = picPixBuff->scale_simple(150,35,Gdk::INTERP_BILINEAR);
}
I have gone through this.
Related Question - How to load a widget as a different thread in gtk? (vala)
There are docs for that. That example does exactly what you are asking for.
These are the functions that do the magic. The example is easy to follow.
// notify() is called from ExampleWorker::do_work(). It is executed in the worker
// thread. It triggers a call to on_notification_from_worker_thread(), which is
// executed in the GUI thread.
void ExampleWindow::notify()
{
m_Dispatcher.emit();
}
void ExampleWindow::on_notification_from_worker_thread()
{
if (m_WorkerThread && m_Worker.has_stopped())
{
// Work is done.
if (m_WorkerThread->joinable())
m_WorkerThread->join();
delete m_WorkerThread;
m_WorkerThread = nullptr;
update_start_stop_buttons();
}
update_widgets();
}
I try to write a simple game using cocos2d-x library.
I created class (named Letter) to spawn sprite with random letter as a label and add a listener because I want to catch touch events.
I've a function:
listener->onTouchEnded = [=](cocos2d::Touch* touch, cocos2d::Event* event)
{
CCLOG("press");
Letter::touchEvent(touch, event);
};
and action:
void Letter::touchEvent(cocos2d::Touch* touch, cocos2d::Event* event)
{
this->removeFromParentAndCleanup(true);
CCLOG("touched MySprite");
}
In my Layer I have a function to spawn instance of Letter class:
{
CCLOG("new letter");
Letter* _letter = Letter::create();
addChild(_letter, 1);
}
And of course in init() i create a one letter:
this->createLetter();
Now, I want to create action which runs after touch to send some information (int) to my Layer, destroy Sprite and run createLetter(); again.
How can I do this? I tried create CC_CALLBACK_1 and something but I don't have idea what I need to do. :(
I'm not C++ master but I think I've basic knowledge about C++, I'm a system administrator, but I would like to try something net.
Thank you for help.
User this->getParent() in Latter class to access Layer class from and then call any method written there incuding createLetter() or any new method to pass integer.
#
YourLayerClass* layerObject = (YourLayerClass*)this->getParent();
layerObject->sendData(3);
layerObject->createLetter();
this->removeFromParentAndCleanup(true);
For testing software with Google Espresso test-framework I have following issue:
At start of the program, a splash screen starts and initialises the entire application. After this, I start an Activity which asks for input.
In Espresso, the application starts and the test starts with following code:
onView(withId(R.id.chooseBookTitle)).perform(click());
This crashes, because the display still shows the splash screen and the chooseBookTitle is only visible afterwards. How to prevent that Google-Espresso will click the key before it is there?
(I don't want to insert wait loops, but keep it event driven. In worse case, I go back to Robotium)
Please check the IdlingResource interface:
As mentioned by Stefano Dacchille (see sample below) you must create an idling ressource implementation that waits to become idle:
public class WaitForSomethingResource implements IdlingResource {
ResourceCallback mResourceCallback;
private boolean isIdle;
#Override
public String getName() {
return WaitForSomethingResource.class.getName();
}
#Override
public void registerIdleTransitionCallback(
ResourceCallback resourceCallback) {
mResourceCallback = resourceCallback;
}
#Override
public boolean isIdleNow() {
return isIdle;
}
/**
* Register an listener, use an event bus or something
* else to get notified about any change you want to track.
*/
public void onProgressChanged() {
isIdle = true;
if (isIdle && mResourceCallback != null) {
mResourceCallback.onTransitionToIdle();
}
}
}
After that, you have to register the IdlingResource implementation within the tests setUp() or #before method by writing:
Espresso.registerIdlingResource(waitForSomethingResource)
Sample:
http://dev.jimdo.com/2014/05/09/wait-for-it-a-deep-dive-into-espresso-s-idling-resources/
API Doc:
http://developer.android.com/reference/android/support/test/espresso/IdlingResource.html#isIdleNow()
From what I see, you should open directly the activity that contains R.id.chooseBookTitle, otherwise your view will never be on the screen so your test will always fail because Espresso can't find the specified view.
Otherwise, I use Thread.sleep(...) before I do some tests to make the tests wait. Try it before calling onView(withId(R.id.chooseBookTitle)).perform(click()); and see if it's working.
Good luck!
I have a cascades project where I use the MediaPlayer class in cpp.
I have defined a handler class, which handles metaDataChanged event, but when I set the source url and call mediaPlayer.prepare() method, it doesn't retrieve anything in metadata, so it's simply empty QVariantMap.
What's interesting is that defined event handler for metaDataChaned event is not even called.
I think there could be something that I can add here to be able to get the metadata, however prepare() method workds sucessfully, so I don't know what's the problem
here is a piece of code I've tried.
bb::multimedia::MediaPlayer* mp = new bb::multimedia::MediaPlayer();
mp->setSourceUrl(resultString);
mp->prepare();
MetaDataReader metaDataReader(mp);
and a class
MetaDataReader::MetaDataReader(bb::multimedia::MediaPlayer* mediaPlayer) : QObject(NULL)
{
connect(mediaPlayer, SIGNAL(metaDataChanged(const QVariantMap&)), this, SLOT(onMetaDataChanged(const QVariantMap&)));
}
void MetaDataReader::onMetaDataChanged(const QVariantMap& metaData)
{
someCode
// It doesn't reach this SLOT
}
How can I get the metadata here?
thanks in advance
It's a bit odd, but you may not get metadata until you start playback for the file. Try starting playback, and you should see the metaDataChanged signal get fired shortly after.
I have a version hit check right after my application gets start.
But when simulator is loading its sending the request and all that stuff. After my application starts it give version hit value NULL but after I close the application and open it again it gives the correct value.
1) My Question is that Why is this behavior occurring and what should I do that app starts and version check gives correct value at first attempt!
2) And the app is even not executed by user why its line of codes are executed?????
public MyScreen() {
Bitmap bitmap = Bitmap.getBitmapResource("background.png");
this.getMainManager().setBackground(
BackgroundFactory.createBitmapBackground(bitmap));
synchronized (Application.getEventLock())
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Status.show("Please Wait...", Bitmap.getPredefinedBitmap(Bitmap.INFORMATION), 1000);
LoginScreen();
}
});
}
Now what does it do is that it shows only the background screen and nothing happens no service but when I start it again it works. Whats the problem? Thanks
If your MyScreen class is actually a kind of Screen (through inheritance), then there's no need for you to synchronize on the event lock in this case. The constructor for a Screen will already be called on the UI thread, so, just simplify your code to:
public MyScreen() {
Bitmap bitmap = Bitmap.getBitmapResource("background.png");
this.getMainManager().setBackground(
BackgroundFactory.createBitmapBackground(bitmap));
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Status.show("Please Wait...", Bitmap.getPredefinedBitmap(Bitmap.INFORMATION), 1000);
LoginScreen();
}
});
Also, you might be able to get rid of the invokeLater() call, too, leaving you with this:
public MyScreen() {
Bitmap bitmap = Bitmap.getBitmapResource("background.png");
this.getMainManager().setBackground(
BackgroundFactory.createBitmapBackground(bitmap));
Status.show("Please Wait...", Bitmap.getPredefinedBitmap(Bitmap.INFORMATION), 1000);
LoginScreen();
You would normally use invokeLater() if you just wanted to safely initiate the code inside its run() method from a background thread, or if you wanted to queue it to be run after the constructor finishes.
But, if you're ready for it to happen right away, and you were just using that call to ensure that
Status.show("Please Wait...", Bitmap.getPredefinedBitmap(Bitmap.INFORMATION), 1000);
LoginScreen();
was run on the UI thread, then there's no need for that, because as I said, you're already on the UI thread in the MyScreen constructor.
But, I also can't see what you do at the end of your MyScreen constructor, so it's possible that using invokeLater() is appropriate.
Post some more information in response to my comment above, and I'll try to help with more.