apache / apache/cordova-plugin-media
In Android include webView cookies for streaming in setDataSource()
- Dominant language
- JavaScript
- Stars
- 391
- Forks
- 762
- PR merge metrics
- No merged PRs in 30d
Description
# Feature Request
## Motivation Behind Feature
On Android I am unable to stream mp3 files that require authentication header to access.
I've set this as a feature because it looks like it was never intentionally implemented, HOWEVER, it might be a bug if other users are not experiencing this problem.
Note: I am using Capacitor.
## Feature Description
The media.create function would include an additional boolean parameter to indicate whether the streaming file should include headers, or an array of headers to include.
AFAICT this is only a problem on Android. I'm surprised that this doesn't work or hasn't been implemented so maybe I'm doing something wrong:
Using the cordova-plugin-filetransfer I am able to download files that require authentication. When I look at the Java code I see there is a function that pulls the cookie's from webview and includes them in the header with the file request.
When I look at the Java code for cordova-plugin-media I see this, which does not include any headers
` if (this.isStreaming(file)) {
this.player.setDataSource(file);`
And looking at the API for setDataSource, it looks like I can include the headers. But it also says that they might already be managed by the apps own CookieManager.
https://developer.android.com/reference/android/media/MediaPlayer#setDataSource(android.content.Context,%20android.net.Uri,%20java.util.Map%3Cjava.lang.String,%20java.lang.String%3E,%20java.util.List%3Cjava.net.HttpCookie%3E)
## Alternatives or Workarounds
- I am able to playback files that do not require authentication.
- I am able to download with fileTransfer files that require authentication.
- I could download the files before playing them back. But that's not a great experience.
- I could also add an endpoint to the API to create a token for the file url to authenticate that way, but that would be fairly involved as well.
Contributor guide
Research direction
Start by tracing the Android streaming branch in media.create and compare its setDataSource(file) call with the Android MediaPlayer overload that accepts headers or cookies. Check how the WebView CookieManager is used by the fileTransfer plugin, then verify that authenticated MP3 streaming works without breaking unauthenticated playback.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java, javascript
- Domain
- mobile-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100