Skip to content

Play files stored in flutter assets #36

Description

@andreasgangso

This is currently possible, at least on android, but very hard to use.
You need to start your url with asset:///flutter_assets/, so e.g. for "assets/demo.mp4", it would look like this:

  MediaItem(
    url: 'asset:///flutter_assets/assets/demo.mp4',
    mimeType: 'video/mp4',
    metadata: MediaMetadata(title: 'Asset file'),
  ),

Instead, we should implement something similar to video_player:

  1. add a way to signal that this is an asset file, e.g. add a UrlType in the MediaItem pigeon.
  2. on the native side, use something like (untested):
    // Android
    val path = FlutterInjector.instance().flutterLoader().getLookupKeyForAsset(mediaItem.url)
    val exoMediaItemUrl = "asset:///" + path;
    // iOS
    let assetKey = registrar?.lookupKey(forAsset: mediaItem.url)
    let path = Bundle.main.path(forResource: assetKey, ofType: nil)!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions