Finally I got solution after research for a long time :-)
Summary answer for this question
Don't forget to add headers
in BetterPlayerDataSource
Don't use this format "https://drive.google.com/uc?export=view&id=${fileId}"
and
Use this format "https://www.googleapis.com/drive/v3/files/${fileId}?alt=media"
For guys who face issue like me, please follow these step
- Enable Drive API
- Integrate google login in your app with appropriate
Scpoe
, for me driveReadonlyScope
is enough.
- Retrieve
fileId
Next step that I stuck is
- Don't forget to add
headers
in BetterPlayerDataSource
- Don't use this format
"https://drive.google.com/uc?export=view&id=${fileId}"
and
- Use this format
"https://www.googleapis.com/drive/v3/files/${fileId}?alt=media"
Like this
BetterPlayerDataSource betterPlayerDataSource = BetterPlayerDataSource(
BetterPlayerDataSourceType.network,
"https://www.googleapis.com/drive/v3/files/$fileId?alt=media",
videoExtension: ".mp4",
headers: getDataFromCache(CacheManagerKey.authHeader),
);
authHeader
can get when you call signWithGoogle function,
I save it and retrieve later. In signWithGoogle
function, you can get authHeader using this
Map<String, String> authHeader = await googleSignIn.currentUser!.authHeaders;
Bonus - Queries For You.
- Get Share With Me Data = >
q: "'sharedWithMe = true and (mimeType = 'video/mp4' or mimeType = 'application/vnd.google-apps.folder')"
- Get Share Drive Data =>
q: "'shared_drive_id' in parents and trashed=false and (mimeType = 'video/mp4' or mimeType = 'application/vnd.google-apps.folder')"
,
- Get My Drive Data =>
q: "'root' in parents and trashed=false and (mimeType = 'video/mp4' or mimeType = 'application/vnd.google-apps.folder')"
,