Configure local media playback

Play media files that are stored locally on an Android device.


The Android SDK allows you to play media files that are stored locally on a device.

Requirements

ItemDescription
Supported file format.mp4

When downloading videos from the web, opt for .mp4 conversions of the video asset. Streaming protocols like HLS or DASH have limited utility in an offline scenario and would require you to rewrite the manifest to account for the local segments.
File pathLocal path must use the file:/// protocol

Enable playback

📘

BEST PRACTICE APP

You can also refer to our JW Player SDK for Android - Local Asset Playback. This application contains an example implementation of loading local video assets into the JW Player SDK for Android.

  1. Clone the repository into your Android Studio workspace: git clone [email protected]:jwplayer/jwplayer-android-best-practice-apps.git.
  2. Open Android Studio and select Open an existing Android Studio project.
  3. Navigate to the jwplayer-android-best-practice-apps directory and select the LocalAssetPlayback folder.
  4. Open the AndroidManifest.xml file and replace {your_license_key} with your license key.

To enable local content playback, use the following steps:

  1. Decide where the local media file is stored. On an Android device, local media files can be stored in either the /assets folder, /temp folder, or temp folder of your choice.
FolderUse case
/assets• Media file is preloaded with the app

• User selects a personal media file that already exists on the device
/tempMedia file was downloaded from the internet when the device was last online

You may want to use the Android Download Manager to download the video from the internet.
  1. Identify the absolute file path to the media file.

    Accessing the local file system on Android will differ depending on which version of Android you are building against and your application's use case. To learn more about external file access on Android refer to the Android Data and file storage overview.
  2. Add the file path to a PlaylistItem.
mPlayerView = findViewById(R.id.jwplayer);
    PlaylistItem playlistItem = new PlaylistItem.Builder()      
        .file("file:///local/path/file.mp4")
        .build();

    List<PlaylistItem> playlist = new ArrayList<>();
    playlist.add(playlistItem);
    PlayerConfig config = new PlayerConfig.Builder()
        .playlist(playlist)
        .build();
    mPlayerView.setup(config);


Did this page help you?