Search code examples
javaprocessruntimemovie

Creating, controlling, and destroying a Movie in Java


I'm trying to make a piece of software that will start a movie (.m4v) in the default movie viewer, let the movie run and close it when required. I was thinking using process but after some messing around with it and some google searches, I've been unable to figure out how to implement such a thing. Here's what I have:

Runtime runTime = Runtime.getRuntime();
    try {
        Process process = runTime
                .exec("A:\\test.m4v");
    } catch (IOException e) {
        e.printStackTrace();
    }

I get the error: java.io.IOException: Cannot run program "A:\test.m4v": CreateProcess error=193, %1 is not a valid Win32 application What am I doing wrong? What do I need to do to start this movie? What do I need to do as well to make the movie full screen?


Solution

  • Try putting wmplayer.exe /play /close A:\\test.m4v in your .exec method if you know the .m4v can be viewed on Windows Media Player. Or simply choose a different compatible player instead of Mplayer2.exe.

    This /close command automatically closes the player once the video reaches the end.

    e.g. The below code snippet opens the WMedia Player and plays the mp4 video in fullscreen mode.

    Runtime runTime = Runtime.getRuntime();
    try {
        Process process = runTime.exec("C:\\Program Files\\Windows Media Player\\wmplayer.exe /play /fullscreen C:\\56775-download.mp4");
    } catch (IOException e) {
        e.printStackTrace();
    }