Configure local media playback (Android)

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

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.


  1. 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);