-
-
Save caprica/52b1793500626cdc88d756175cf9aa4c to your computer and use it in GitHub Desktop.
An example showing how to use "callback" media to read media data from an InputStream. This is NOT recommended and has severe, often critical, limitations. Working with a MemoryMappedByteBuffer would be better.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import uk.co.caprica.vlcj.factory.MediaPlayerFactory; | |
import uk.co.caprica.vlcj.media.callback.CallbackMedia; | |
import uk.co.caprica.vlcj.media.callback.nonseekable.NonSeekableInputStreamMedia; | |
import uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent; | |
import javax.swing.*; | |
import java.awt.event.WindowAdapter; | |
import java.awt.event.WindowEvent; | |
import java.io.IOException; | |
import java.io.InputStream; | |
public class MinimalMediaCallbackTest { | |
public static void main(String[] args) throws Exception { | |
final EmbeddedMediaPlayerComponent mediaPlayerComponent = new EmbeddedMediaPlayerComponent(); | |
JFrame f = new JFrame("Test Player"); | |
f.setSize(800, 600); | |
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
f.addWindowListener(new WindowAdapter() { | |
@Override | |
public void windowClosing(WindowEvent e) { | |
mediaPlayerComponent.release(); | |
} | |
}); | |
f.setContentPane(mediaPlayerComponent); | |
f.setVisible(true); | |
CallbackMedia media = new NonSeekableInputStreamMedia() { | |
@Override | |
protected InputStream onOpenStream() throws IOException { | |
// Get your input stream to read from here... | |
return null; | |
} | |
@Override | |
protected void onCloseStream(InputStream inputStream) throws IOException { | |
inputStream.close(); | |
} | |
@Override | |
protected long onGetSize() { | |
return 0; | |
} | |
}; | |
mediaPlayerComponent.mediaPlayer().media().play(media); | |
Thread.currentThread().join(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment