Skip to content

Play files stored in flutter assets #36

@andreasgangso

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)!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions