spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

SOLVED - JavaFx MediaPlayer - Cannot allocate memory or OutOfMemory


A simple and fully functional example:
(This is my small contribution with community, hope this helps someone)

import java.io.File;

import javafx.application.Application;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Stage;

public class MediaPlayerSample extends Application
{

    private File[]      files;
    private int         nextIdx;
    private MediaPlayer activePlayer;

    public static void main(String[] args) {
        launch(args);
    }

    private void playNext() {
        if (files == null || files.length == 0) {
            return;
        }

        Media media = new
Media(files[nextIdx++].toURI().toString());
        if (nextIdx >= files.length) {
            nextIdx = 0;
        }

        if (activePlayer != null) {
            activePlayer.stop();
            // This is the magic code
            activePlayer.dispose();
        }

        activePlayer = new MediaPlayer(media);
        activePlayer.setOnEndOfMedia(new
Runnable() {
            @Override
            public void run() {
                playNext();
            }
        });

        activePlayer.play();
    }

    @Override
    public void start(Stage primaryStage) throws
Exception {
        File fDir = new File("/mp3-files/");
        files = fDir.listFiles();
        playNext();
    }

}

Categories : Java

Related to : SOLVED - JavaFx MediaPlayer - Cannot allocate memory or OutOfMemory
JavaFX MediaPlayer "Error: 80de0001 in CallbackToJava..."
I don't know if you haven't found a solution yet... I had the same problem and solved it by following code: setOnDragDropped(new EventHandler<DragEvent>() { @Override public void handle(DragEvent event) { System.out.println("onDragDropped"); event.setDropCompleted(true); }

Categories : Eclipse
Why do my JavaFX application's drag routines break in JavaFX 8?
I don't have time to create a full example with the error of your code. So here's one of my own examples, extended with a StackPane, to show you how it works: import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.Cursor; import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.inpu

Categories : Java
How to allocate?
$capture_field_vals=Array(); foreach($_POST["mytext"] as $key => $text_field){ array_push($capture_field_vals,$text_field); } Then $insert2 = "INSERT INTO tabel2(number1, number2, number3, number4) VALUES('$capture_field_vals[0]','$capture_field_vals[1]','$capture_field_vals[2]','$capture_field_vals[3]')";

Categories : PHP
Why mediaplayer of my app is not acting as actual music player
It sounds like you are having issues with audio focus. That is why you are having issues with audio playing while on a call or while other players are in use. You should look into the AudioManager to help you with that. The developer site also has a training and guide regarding audio focus and media playback. You should be able to find the example source in /sample/android-21/legacy folder if you

Categories : Android
m3u8 Video stops with MediaPlayer: Error (1,-1004)
looks like you play HLS resource via low network connection or server is busy and you cannot reach it. in this case, android tries to fetch next playlist but fails to connect to server, and after several attempts rises this error. i think you can simply notify users about bad connection and suggest to reconnect to the server :)

Categories : Android
Recently Add
Redirecting the output directory of 'mvn package' or 'mvn compile' command
No suitable constructor found for ProductoExtranjero
java Composite design pattern(Directory &File)
Java JTree's ui refresh after removing node from parent
First REST Spring application
How to cancel Indexing of a Solr document using Update Request Processor
PowerMock - Mock a Singleton with a Private Constructor
Calling a Postgres stored function SQL error
Where to store Morphlines Java custom command class?
Generic repository using map
How can I scroll a ScrolledComposited in Eclipse SWT Design view?
2 Frames/layout in 1 Activity
Writing a switch differently
Next button opens another activity when its reaches the array limit
Is EclipseLink MOXy capable of applying JSR-303 Bean Validation when unmarshalling XML to object?
Why my jdk can't work,and before the java_home, there is a space that is not from me
How to add List of objects in a Map
How to make notepad++ function like regular notepad in cmd?
Cell renderer and the lost focus
how can I implement iterable for LinkedList>
Disable Androids image-crunch in eclipse (run as) builds
java 8 lambda myMap.stream().count() != myMap.size() after merging myMap
Issue with Calendar calculation that spans 2 calendar years
JSF 2.0 Spring bean injection
Java Regex ReplaceAll with grouping
Getting any word and last word using sed
Clicking on link on JEditorPane throws IOException
printing out difference of two arrays
Spring Bean Alias in JavaConfig
Using Factory Method to Create Generics
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.