Best Practices and Troubleshooting
Consider the following best practices when developing JavaFX Media applications:
- Media width, height, and duration are unavailable as soon as the source file is set
- Playback stops when the current time reaches the buffer head
- Buffer progress is not updated on Windows if the player pauses when it reaches the buffer head
- On a very slow network with excessive network latency, playing a streaming media even though supported by the platform throws an
UnsupportedMediaException
Issue: Media width, height, and duration are unavailable as soon as the source is set. If you expect to obtain the width, height, or duration of a streaming media as soon as the source is set, you might get the default value.
Workaround: Bind the width, height, or duration to the on replace trigger, and you get the correct value when the trigger's value is changed. For example:
var screenHeight = bind myMedia.height on replace { .. }
Issue: Playback stops when the current time reaches the buffer head. When a streaming media is playing over a slow network, the playback pauses if it reaches the buffer head. It will not play again without user or program intervention, even though the buffer is progressing.
Workaround: Whether or not you set the player to the autoPlay mode, the workaround is to detect this pause when the current time is greater than zero and to programmatically enable playing after suitable buffer progress is detected. The application developer should evaluate how much buffer progress is needed.
Issue: Buffer progress is not updated on Windows if the player pauses when it reaches the buffer head. The application might display progress when playing a streaming media and pause because the current time reaches the buffer head. Even though the buffer is progressing inside the engine, the buffer progress is not updated.
Workaround: To enable displaying the buffer progress, fetch or pseudo-update metadata such as volume. This action triggers updating of the buffer progress variable.
Issue: On a very slow network with excessive network latency, playing even a streaming media supported by the platform throws an UnsupportedMediaException. On a very slow network with high latency, capturing enough of the stream to determine the type and its metadata might not always be possible. In such cases the engine times out and reports an UnsupportedMediaException.
Workaround: No real workaround exists for this issue. One solution is to play the media again so that the engine can gather enough data from the downloaded cache to enable further playback of the media.
We welcome your participation in our community. Please keep your comments civil and on point. You may optionally provide your email address to be notified of repliesyour information is not used for any other purpose. By submitting a comment, you agree to these Terms of Use.
Sandeep Konchady
Staff Engineer, Sun Microsystems
Alla Redko
Technical Writer, Sun Microsystems
Larry McDonough
Engineering Manager, Sun Microsystems