-
Notifications
You must be signed in to change notification settings - Fork 29.3k
Open
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: desktopRunning on desktopRunning on desktopa: pluginsSupport for writing, building, and running plugin packagesSupport for writing, building, and running plugin packagesengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.platform-iosiOS applications specificallyiOS applications specificallyplatform-macBuilding on or for macOS specificallyBuilding on or for macOS specificallyteam-macosOwned by the macOS platform teamOwned by the macOS platform teamtriaged-macosTriaged by the macOS platform teamTriaged by the macOS platform team
Description
While working on macOS support for video_player
I discovered that lookupKeyForAsset:
doesn't seem to do what the docs suggest, and it doesn't seem to work the way it needs to on macOS; code that works in that plugin for loading videos from assets on iOS does not work on macOS.
The docs say:
/**
* Returns the file name for the given asset. If the bundle with the identifier
* "io.flutter.flutter.app" exists, it will try use that bundle; otherwise, it
* will use the main bundle. To specify a different bundle, use
* `+lookupKeyForAsset:fromBundle`.
*
* @param asset The name of the asset. The name can be hierarchical.
* @return the file name to be used for lookup in the main bundle.
*/
What it actually seems to return is not a file name, but a relative path from the main bundle. That appears to work for NSBundle lookup on iOS (I'm actually not sure why it does work), but not on macOS. The video_player
example app's flow is:
iOS
- Dart code requests loading of the asset
assets/Butterfly-209.mp4
. - Native code calls
lookupKeyForAsset:@"assets/Butterfly-209.mp4"
on the registrar and gets backFrameworks/App.framework/flutter_assets/assets/Butterfly-209.mp4
(the relative path from the main bundle). - Native code calls
[[NSBundle mainBundle] pathForResource:<the path above> ofType:nil]
and gets back an absolute path. - Native code loads that video.
macOS
- Dart code requests loading of the asset
assets/Butterfly-209.mp4
. - Native code calls
lookupKeyForAsset:@"assets/Butterfly-209.mp4"
on the registrar and gets backContents/Frameworks/App.framework/Resources/flutter_assets/assets/Butterfly-209.mp4
(still the correct relative path from the main bundle). - Native code calls
[[NSBundle mainBundle] pathForResource:<the path above> ofType:nil]
and gets backnil
. - Native code fails to load the video because the path is
nil
.
So while our API does itself have the same behavior on macOS and iOS, that behavior doesn't actually work for what it's supposed to do on macOS.
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: desktopRunning on desktopRunning on desktopa: pluginsSupport for writing, building, and running plugin packagesSupport for writing, building, and running plugin packagesengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.platform-iosiOS applications specificallyiOS applications specificallyplatform-macBuilding on or for macOS specificallyBuilding on or for macOS specificallyteam-macosOwned by the macOS platform teamOwned by the macOS platform teamtriaged-macosTriaged by the macOS platform teamTriaged by the macOS platform team