Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[expo-av] allow playing media files from apk res folder #8936

Merged
merged 2 commits into from
Jun 25, 2020

Conversation

esamelson
Copy link
Contributor

@esamelson esamelson commented Jun 24, 2020

Why

ref #8888 -- expo-av currently does not support playing media files from an android apk's res/raw folder, which is where the RN packager embeds required assets by default.

How

RN's asset source resolver sets the uri for assets embedded in res to simply the resource name with no scheme. Therefore, if the url provided to expo-av has no scheme, we can assume it comes from RN's asset source resolver and is a resource name. (We do the same thing in expo-file-system.)

Found a couple of sources for how to read from resources in MediaPlayer and ExoPlayer (but I am no expert on either library!).

Test Plan

Tested using the repo provided in #8888 and confirmed that with expo-updates disabled, after this change, the audio file played as expected both with ExoPlayer and with androidImplementation: 'MediaPlayer'.

@github-actions
Copy link
Contributor

Native Component List for this branch is ready

Copy link
Contributor

@sjchmiela sjchmiela left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not an expert either, but it looks good to me (especially since it worked)! One missing thing maybe is the changelog entry. 😃

@esamelson esamelson merged commit 450147a into master Jun 25, 2020
@esamelson esamelson deleted the @eric/expo-av-res branch June 25, 2020 00:45
@jonathanstiansen
Copy link

@esamelson this is super exciting 😃! May I ask, how do I track when this goes into a release?

@sasweb
Copy link

sasweb commented Jan 11, 2021

@esamelson just 2 short questions regarding this PR.

  1. Should this be documented in the docs? At the moment there is neither a guide how to use assets from bundled project nor a guide which approach to choose. Imo static assets should always be loaded from the bundled project.
  2. This approach should also work for iOS. Of course there is no res folder on iOS but assets can be stored in ios root folder. I think this doesn't work atm, right? Same with documentation here.

Jamedjo pushed a commit to Jamedjo/expo that referenced this pull request Feb 4, 2021
# Why

ref expo#8888 -- expo-av currently does not support playing media files from an android apk's `res/raw` folder, which is where the RN packager embeds required assets by default.

# How

RN's asset source resolver sets the `uri` for assets embedded in `res` to simply the resource name with no scheme. Therefore, if the url provided to expo-av has no scheme, we can assume it comes from RN's asset source resolver and is a resource name. ([We do the same thing in expo-file-system.](https://github.com/expo/expo/blob/1b61af26782c89da45ba559e60ebb2a38b6e80b3/packages/expo-file-system/android/src/main/java/expo/modules/filesystem/FileSystemModule.java#L312-L314))

# Test Plan

Tested using the repo provided in expo#8888 and confirmed that with expo-updates disabled, after this change, the audio file played as expected both with ExoPlayer and with `androidImplementation: 'MediaPlayer'`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants