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

feat: fileContentProvider resolver #449

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
android:theme="@style/AppTheme">
<profileable android:shell="true"
tools:targetApi="q" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.noxplay.noxplayer.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
<activity
android:name="com.noxplay.noxplayer.MainActivity"
android:supportsPictureInPicture="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import android.provider.MediaStore
import android.provider.Settings
import android.util.Log
import android.view.WindowManager
import androidx.core.content.FileProvider
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
import com.facebook.react.bridge.WritableArray
import com.facebook.react.bridge.WritableNativeArray
import java.io.File


class NoxAndroidAutoModule(reactContext: ReactApplicationContext) :
Expand Down Expand Up @@ -83,7 +85,8 @@ class NoxAndroidAutoModule(reactContext: ReactApplicationContext) :
}

@ReactMethod fun getUri(uri: String, callback: Promise) {
callback.resolve(Uri.parse(uri).toString())
callback.resolve(FileProvider.getUriForFile(reactApplicationContext,
"${BuildConfig.APPLICATION_ID}.provider", File(uri)).toString())
}

@ReactMethod fun listMediaDir(relativeDir: String, subdir: Boolean, callback: Promise) {
Expand Down
4 changes: 4 additions & 0 deletions android/app/src/main/res/xml/provider_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<paths>
<external-path name="external_files" path="."/>
<cache-path name="name" path="." />
</paths>
15 changes: 11 additions & 4 deletions src/utils/mediafetch/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,21 @@ const regexFetch = async ({
songList: await songFetch(reExtracted[1]!, favList, progressEmitter),
});

const resolveURL = async (song: NoxMedia.Song) => ({ url: song.bvid });
const resolveURL = async (song: NoxMedia.Song) => {
let cover: string | undefined = undefined;
if (Platform.OS === 'android') {
const artworkUri = await cacheAlbumArt(song.bvid);
cover = await NoxAndroidAutoModule.getUri(artworkUri);
}
return { url: song.bvid, cover };
};

const resolveArtwork = async (song: NoxMedia.Song) => {
if (Platform.OS === 'android') return '';
let artworkBase64 = '';
try {
const artworkURI = await cacheAlbumArt(song.bvid);
NoxAndroidAutoModule.getUri(artworkURI).then(console.debug);
artworkBase64 = await RNFetchBlob.fs.readFile(artworkURI, 'base64');
const artworkUri = await cacheAlbumArt(song.bvid);
artworkBase64 = await RNFetchBlob.fs.readFile(artworkUri, 'base64');
} catch (e) {
logger.warn(`[localResolver] cannot resolve artwork of ${song.bvid}`);
}
Expand Down
Loading