cordova-plugin-media icon indicating copy to clipboard operation
cordova-plugin-media copied to clipboard

Android 11 Media player not working , Android SDK 30

Open 21pg opened this issue 4 years ago • 13 comments

Bug Report

After I upgrade to android 11 , I am getting problem with cordova-plugin-media player. Its not playing audio stream .. on checking status its always at 1.

Problem

What is expected to happen?

It should play audio stream..

What does actually happen?

A continuous loop is going on play button.

Information

Command or Code

 `<?xml version="1.0" encoding="UTF-8"?>
 <widget xmlns="http://www.w3.org/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" 
  xmlns:gap="http://phonegap.com/ns/1.0" id="app.*********" version="3.6.1" android-versionCode="28">
 <name>******</name>
 <description />
 <author href="444656972743" email="">*********</author>
 <preference name="orientation" value="portrait" />
 <preference name="fullscreen" value="false" />
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
<preference name="android-build-tool" value="gradle" />
<preference name="SplashScreenDelay" value="3000" />
<preference name="AllowInlineMediaPlayback" value="true" />
<preference name="MediaPlaybackRequiresUserAction" value="false" />
<preference name="android-minSdkVersion" value="22" />
<preference name="android-targetSdkVersion" value="30" />
<feature name="NetworkStatus">
  <param name="android-package" value="org.apache.cordova.networkinformation.NetworkManager" />
</feature>
 <feature name="SocialSharing">
  <param name="android-package" value="nl.xservices.plugins.SocialSharing" />
 </feature>
 <feature name="InAppBrowser">
  <param name="android-package" value="org.apache.cordova.inappbrowser.InAppBrowser" />
 </feature>
 <feature name="Notification">
  <param name="android-package" value="org.apache.cordova.dialogs.Notification" />
 </feature>
 <feature name="PushPlugin">
  <param name="android-package" value="com.plugin.gcm.PushPlugin" />
  </feature>
  <plugin name="cordova-plugin-keyboard" source="npm" spec="1.2.0" />
 <plugin name="cordova-plugin-device" source="npm" spec="1.1.7" />
  <platform name="android">
  <preference name="AndroidXEnabled" value="true" />
  <preference name="AndroidInsecureFileModeEnabled" value="true" />
  <resource-file src="google-services.json" target="app/google-services.json" />
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <icon src="icons/android-ldpi.png" density="ldpi" />
  <icon src="icons/android-mdpi.png" density="mdpi" />
  <icon src="icons/android-hdpi.png" density="hdpi" />
  <icon src="icons/android-xhdpi.png" density="xhdpi" />
  <icon src="icons/android-xxhdpi.png" density="xxhdpi" />
  <icon src="icons/android-xxxhdpi.png" density="xxxhdpi" />
  <icon src="icons/android-xxhdpi.png" density="fr-xxhdpi" />
  <splash src="splashscreen/android-ldpi.png" density="ldpi" />
  <splash src="splashscreen/android-mdpi.png" density="mdpi" />
  <splash src="splashscreen/android-hdpi.png" density="hdpi" />
  <splash src="splashscreen/android-xhdpi.png" density="xhdpi" />
  <splash src="splashscreen/android-xxhdpi.png" density="fr-xhdpi" />
  <splash src="splashscreen/android-xxhdpi.png" density="land-xxhdpi" />
  <splash src="splashscreen/android-xxhdpi.png" density="port-xxhdpi" />
  <splash src="splashscreen/android-xxxhdpi.png" density="xxxhdpi" />
  <preference name="KeepRunning" value="true" />
  </platform>
  <access origin="*" subdomains="true" />
  <allow-intent href="http://*/*" />
  <allow-intent href="https://*/*" />
  <allow-intent href="tel:*" />
 <allow-intent href="sms:*" />
 <allow-intent href="mailto:*" />
 <allow-intent href="geo:*" />
 <allow-navigation href="https://www.youtube.com/*" />
 <allow-navigation href="http://www.youtube.com/*" />
 <allow-navigation href="https://player.vimeo.com/*" />
 <allow-navigation href="http://player.vimeo.com/*" />
 <plugin name="cordova-plugin-media" spec="~5.0.3">
  <variable name="KEEP_AVAUDIOSESSION_ALWAYS_ACTIVE" value="NO" />
 </plugin>
 <plugin name="cordova-plugin-androidx-adapter" source="npm" spec="1.1.1" />
 <plugin name="cordova-plugin-camera" source="npm" spec="4.0.3" />
 <plugin name="cordova-plugin-inappbrowser" source="npm" spec="4.0.0" />
 <plugin name="cordova-plugin-globalization" source="npm" spec="1.0.9" />
 <plugin name="cordova-plugin-network-information" source="npm" spec="2.0.1" />
 <plugin name="cordova-plugin-splashscreen" spec="^4.0.3" />
 <plugin name="cordova-plugin-x-socialsharing" source="npm" spec="6.0.0" />
 <plugin name="cordova-plugin-dialogs" source="npm" spec="2.0.1" />
 <plugin name="cordova-sqlite-evcore-extbuild-free" spec="0.14.0" source="npm" />
 </widget>`

Environment, Platform, Device

android 10.0.1

Version information

Checklist

  • [x] I searched for existing GitHub issues
  • [x] I updated all Cordova tooling to most recent version
  • [x] I included all the necessary information above

21pg avatar Sep 28 '21 06:09 21pg

Nothing works for me.. I Have an app builder, In which 20K apps that depends on this plugin (required this feature)- I don't required to record and play. We use live stream e.g (-[(http://streams.radiobob.de/bob-chillout/aac-64/streams.radiobob.de/)]) and just want to play this audio stream on button click.. When I click play button, output is: Error: 1

21pg avatar Sep 29 '21 10:09 21pg

This is the same alike on StackOverflow, nothing but some config file, without the least code or stack-trace - which isn't reproducible. For me it probably would be easy to fix (besides I see no motivation to do so)... better cut all this abstract fluff out and provide hard facts. Nobody cares what you do with that plugin... this doesn't make the issue any more important, but rather raises the question why you don't reinvest in software maintenance?

syslogic avatar Sep 29 '21 12:09 syslogic

This is the same alike on StackOverflow, nothing but some config file, without the least code or stack-trace - which isn't reproducible. For me it probably would be easy to fix (besides I see no motivation to do so). better cut all this abstract fluff out and provide hard facts. Nobody cares what you do with that plugin... this doesn't make the issue any more important, but rather raises the question why you don't reinvest in software maintenance?

I truly expected a solution here (If nothing a kind reply at least) I bet you don't care.. but we do care Issue easily reproducible using on Android 11 I used a very basic cordova app with only using cordova-plugin-media and build over android sdk = 30

21pg avatar Sep 29 '21 13:09 21pg

Does the stream offer https:// version? Error code 1 is aborted and android is known to reject non-secure http paths.

Ref: https://github.com/apache/cordova-plugin-media/blob/master/www/MediaError.js#L46

breautek avatar Sep 29 '21 13:09 breautek

Does the stream offer https:// version? Error code 1 is aborted and android is known to reject non-secure http paths.

Ref: https://github.com/apache/cordova-plugin-media/blob/master/www/MediaError.js#L46 Yes stream works on - https also http://streams.radiobob.de/bob-chillout/aac-64/streams.radiobob.de/ I tried few more streams - https://stream1.datenkollektiv.net/ginseng.mp3 https://radiopotsdam-live.cast.addradio.de/radiopotsdam/live/mp3/high/stream.mp3 https://stream1.thepuremix.net/nexusdance_low.aac

21pg avatar Sep 29 '21 14:09 21pg

Yes stream works on - https also

So can this issue be closed? Preferably you should always use https when available. Android starting in API 28 has disabled clear text (e.g. non-encrypted traffic) by default.

If for some reason you cannot use https, then you'll need to allow clear text traffic. Cordova doesn't provide an interface to do this, you'll need to craft the appropriate xml yourself.

breautek avatar Sep 29 '21 22:09 breautek

No, its not working, I said, stream available on both https:// and http:// version I have tried few more stream but its not working, http or https both.. Is there issue anything related to mp3.. ?

21pg avatar Sep 30 '21 14:09 21pg

I've reproduced your issue -- I observed that the media starts but then closes the stream immediately. I'm not sure of the reason.

I also tested it with simply the HTML <audio> controls -- that does appear to work as expected with the https url. Like I mentioned before, android by default blocks http:// urls. Using the HTML5 may be a workaround for you for the time being.

I only tested with https://streams.radiobob.de/bob-chillout/aac-64/streams.radiobob.de/ stream.

breautek avatar Sep 30 '21 15:09 breautek

I am getting issue with mp3 streams only... however, I made changes as per your suggestion using html 5 for now(temporarily), its working for me.. but need any solutions asap...

21pg avatar Oct 05 '21 15:10 21pg

Add this permission in the config.xml file to fix image

EmersonAlves avatar Oct 27 '21 14:10 EmersonAlves

Add this permission in the config.xml file to fix image

Note that using manage external storage permission requires justification when uploading to google play store. Google may reject the app if they believe you don't need broad file system access.

breautek avatar Oct 27 '21 15:10 breautek

Add this permission in the config.xml file to fix image

Tried, but not working for me.. I am getting problem with some stream e.g.- https://streaming.fueralle.org/ginseng.mp3 for some reason I can't use HTML5 ..

21pg avatar Dec 07 '21 17:12 21pg

When I tested streaming with the above example audio file, I didnt see any issues.

My Project

  • cordova-android 10.1.1
  • cordova-plugin-file: 6.0.2
  • cordova-plugin-media: 5.0.4

Test Environment

  • Emulator: Pixel 4 API 31

Use Cases

First Use Case

  • No custom modifications added to config.xml.
  • App content served from default path https://localhost/

Second Use Case

  • Set AndroidInsecureFileModeEnabled to true in config.xml.
  • App content served from file:///android_asset/www/

Notes

  • This test was done before [email protected] release. The outcome shouldnt be effect with the new release.
  • cordova-plugin-file was added by the media plugin. I didn't add it manually.
  • When testing, it took a couple of seconds for the audio to be heard. I suspected it was normal behavior of the stream.
  • If app is served from https scheme trying to stream from the http scheme, it will fail. This is default behavior of any browser since its trying to access something that is insecure.
  • If using LetsEncrypt and running on an old Android device, this might produce unexpected results.

erisu avatar May 25 '22 05:05 erisu