diff --git a/extensions/opus/src/main/java/com/google/android/exoplayer/ext/opus/LibopusAudioTrackRenderer.java b/extensions/opus/src/main/java/com/google/android/exoplayer/ext/opus/LibopusAudioTrackRenderer.java index 5465d5e4c1..a916156e7b 100644 --- a/extensions/opus/src/main/java/com/google/android/exoplayer/ext/opus/LibopusAudioTrackRenderer.java +++ b/extensions/opus/src/main/java/com/google/android/exoplayer/ext/opus/LibopusAudioTrackRenderer.java @@ -119,13 +119,20 @@ public final class LibopusAudioTrackRenderer extends SampleSourceTrackRenderer formatHolder = new MediaFormatHolder(); } + /** + * Returns whether the underlying libopus library is available. + */ + public static boolean isLibopusAvailable() { + return OpusDecoder.isLibopusAvailable(); + } + /** * Get the version of underlying libopus library. * * @return version of the underlying libopus library. */ public static String getLibopusVersion() { - return OpusDecoder.getLibopusVersion(); + return isLibopusAvailable() ? OpusDecoder.getLibopusVersion() : null; } @Override diff --git a/extensions/opus/src/main/java/com/google/android/exoplayer/ext/opus/OpusDecoder.java b/extensions/opus/src/main/java/com/google/android/exoplayer/ext/opus/OpusDecoder.java index 7a5e2b8096..61e82b1859 100644 --- a/extensions/opus/src/main/java/com/google/android/exoplayer/ext/opus/OpusDecoder.java +++ b/extensions/opus/src/main/java/com/google/android/exoplayer/ext/opus/OpusDecoder.java @@ -26,13 +26,21 @@ import java.nio.ByteBuffer; */ /* package */ class OpusDecoder { - private final long nativeDecoderContext; - + private static final boolean IS_AVAILABLE; static { - System.loadLibrary("opus"); - System.loadLibrary("opusJNI"); + boolean isAvailable; + try { + System.loadLibrary("opus"); + System.loadLibrary("opusJNI"); + isAvailable = true; + } catch (UnsatisfiedLinkError exception) { + isAvailable = false; + } + IS_AVAILABLE = isAvailable; } + private final long nativeDecoderContext; + /** * Creates the Opus Decoder. * @@ -81,6 +89,13 @@ import java.nio.ByteBuffer; opusReset(nativeDecoderContext); } + /** + * Returns whether the underlying libopus library is available. + */ + public static boolean isLibopusAvailable() { + return IS_AVAILABLE; + } + /** * Returns the version string of the underlying libopus decoder. */ diff --git a/extensions/vp9/src/main/java/com/google/android/exoplayer/ext/vp9/LibvpxVideoTrackRenderer.java b/extensions/vp9/src/main/java/com/google/android/exoplayer/ext/vp9/LibvpxVideoTrackRenderer.java index a87a5e2590..af900643d6 100644 --- a/extensions/vp9/src/main/java/com/google/android/exoplayer/ext/vp9/LibvpxVideoTrackRenderer.java +++ b/extensions/vp9/src/main/java/com/google/android/exoplayer/ext/vp9/LibvpxVideoTrackRenderer.java @@ -151,12 +151,17 @@ public final class LibvpxVideoTrackRenderer extends SampleSourceTrackRenderer { } /** - * Get the version of underlying libvpx library. - * - * @return version of the underlying libvpx library. + * Returns whether the underlying libvpx library is available. + */ + public static boolean isLibvpxAvailable() { + return VpxDecoder.isLibvpxAvailable(); + } + + /** + * Returns the version of the underlying libvpx library if available, otherwise {@code null}. */ public static String getLibvpxVersion() { - return VpxDecoder.getLibvpxVersion(); + return isLibvpxAvailable() ? VpxDecoder.getLibvpxVersion() : null; } @Override diff --git a/extensions/vp9/src/main/java/com/google/android/exoplayer/ext/vp9/VpxDecoder.java b/extensions/vp9/src/main/java/com/google/android/exoplayer/ext/vp9/VpxDecoder.java index 05cc243401..ad698703fa 100644 --- a/extensions/vp9/src/main/java/com/google/android/exoplayer/ext/vp9/VpxDecoder.java +++ b/extensions/vp9/src/main/java/com/google/android/exoplayer/ext/vp9/VpxDecoder.java @@ -24,13 +24,21 @@ import java.nio.ByteBuffer; */ /* package */ class VpxDecoder { - private final long vpxDecContext; - + private static final boolean IS_AVAILABLE; static { - System.loadLibrary("vpx"); - System.loadLibrary("vpxJNI"); + boolean isAvailable; + try { + System.loadLibrary("vpx"); + System.loadLibrary("vpxJNI"); + isAvailable = true; + } catch (UnsatisfiedLinkError exception) { + isAvailable = false; + } + IS_AVAILABLE = isAvailable; } + private final long vpxDecContext; + /** * Creates the VP9 Decoder. * @@ -54,7 +62,7 @@ import java.nio.ByteBuffer; * @return 0 on success with a frame to render. 1 on success without a frame to render. * @throws VpxDecoderException on decode failure. */ - public int decode(ByteBuffer encoded, int size, OutputBuffer outputBuffer, boolean outputRgb) + public int decode(ByteBuffer encoded, int size, OutputBuffer outputBuffer, boolean outputRgb) throws VpxDecoderException { if (vpxDecode(vpxDecContext, encoded, size) != 0) { throw new VpxDecoderException("libvpx decode error: " + vpxGetErrorMessage(vpxDecContext)); @@ -69,6 +77,13 @@ import java.nio.ByteBuffer; vpxClose(vpxDecContext); } + /** + * Returns whether the underlying libvpx library is available. + */ + public static boolean isLibvpxAvailable() { + return IS_AVAILABLE; + } + /** * Returns the version string of the underlying libvpx decoder. */