How to properly set up a media player javafx
<p>I have created a media player method is javafx which is called upon startup (below is the media player). My problem is that this pauses whenever I interact with a scroll pane by dragging or by zooming the player pauses and does not start again. Why is this the case and how may I fix this(included full application if you would to try it). </p>

<p>Method(Live code)</p>

<pre><code>    private static void MusicPlayer() {
    if(musicList.peek() == null)
    {
        return;
    }
    MediaPlayer mediaPlayer = new MediaPlayer(new Media(new File(musicList.poll()).toURI().toString()));
    mediaPlayer.setOnReady(() -&gt; {
        mediaPlayer.play();
        mediaPlayer.setOnEndOfMedia(() -&gt; {
            mediaPlayer.dispose();
            MusicPlayer();
        });
    });
}
</code></pre>

<p>Minimal</p>

<pre><code>package minimalist;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.stream.Collectors;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Stage;

public class Minimal extends Application{

    private static Queue&lt;String&gt; musicList = new LinkedList&lt;String&gt;();

    public static void main(String[] args) throws IOException {
        List&lt;String&gt; result = Files.find(Paths.get(".\\music"), 100,
                (p, a) -&gt; p.toString().toLowerCase().endsWith(".mp3"))
                .map(path -&gt; path.toString())
                .collect(Collectors.toList());
        for(int a = 0; a &lt; result.size(); a++)
        {
            musicList.add(result.get(a));
        }
        MusicPlayer();
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        ScrollPane scrollpane = new ScrollPane();
        Image image = new Image("https://upload.wikimedia.org/wikipedia/commons/7/70/Kusatma_Zonaro.jpg");
        ImageView imageView = new ImageView(image);
        scrollpane.setContent(imageView);
        scrollpane.setPannable(true);
        Scene scene = new Scene(new StackPane(scrollpane));
        primaryStage.setScene(scene);
        primaryStage.setFullScreen(true);
        primaryStage.show();
    }

    private static void MusicPlayer() {
        if(musicList.peek() == null)
        {
            return;
        }
        MediaPlayer mediaPlayer = new MediaPlayer(new Media(new File(musicList.poll()).toURI().toString()));
        mediaPlayer.setOnReady(() -&gt; {
            mediaPlayer.play();
            mediaPlayer.setOnEndOfMedia(() -&gt; {
                mediaPlayer.dispose();
                MusicPlayer();
            });
        });
    }
}
</code></pre>