2

In my app, I already integrated with google login and I successfully accessed my google drive folder and video files(mp4). But better player can play public video by modified url like this https://drive.google.com/uc?id=my_video_file_id. I want to develop an app like Nplayer or Kudoplayer.

Can anyone guide me some scenario of Nplayer or Kudoplayer? and guide me how to play private drive's video using better player. Thanks.

Wai Han Ko
  • 760
  • 5
  • 16

2 Answers2

2

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')",
Wai Han Ko
  • 760
  • 5
  • 16
0

that's tricky.

I would propably try to attach approprieate headers so google drive would allow me to reach file using BetterPlayerDataSource class.

but being curious and checking how google would want it to be made... I got into spiral of google docs and I found this

https://cloud.google.com/blog/products/identity-security/enhancing-security-controls-for-google-drive-third-party-apps

Keep in mind that downloading file and streaming also differ. So if you want for your player to not lag you should stream.

sonic
  • 1,282
  • 1
  • 9
  • 22
  • Can you share sample header for BetterPlayerDataSource?. I already tested with all drive scope but not working. Thanks! – Wai Han Ko Sep 01 '22 at 02:46
  • @WaiHanKo Sorry I have replied openly. I have never been doing it. I was just pointing direction what I would do. – sonic Sep 01 '22 at 07:39