Friday, January 07, 2005

Loading Video from a Database Table

While playing with Java Player class, I came to the following problem: How to feed the Player with a multimedia stream from a database table, instead of an URL or a MediaLocator. The Java Media Framework (JMF) provides the PullDataSource, but it is useful only when you extend it. So, here is my (very simple, and definitely non-perfect) implementation available for download - the InputStreamDataSource.java, with documentation. It uses my BlobImage class, and loading a media stream from a database table is as simple as:
Player player = Manager.createPlayer(
  new InputStreamDataSource(
      blobImage.load(index), blobImage.getContentType()));

Enjoy!