[Android only] Audio file doesn't play
See original GitHub issueimport {Media, MediaObject} from "@ionic-native/media/ngx";
constructor(
private media: Media,
) { }
const mp3file: MediaObject = this.media.create(url);
mp3file.play();
On iOs the code above is working properly, however on Android no sound is coming out and I have no error message.
Any idea ?
_Ionic:
Ionic CLI : 5.4.15 Ionic Framework : @ionic/angular 5.0.0 @angular-devkit/build-angular : 0.803.23 @angular-devkit/schematics : 8.1.3 @angular/cli : 8.1.3 @ionic/angular-toolkit : 2.1.2
Cordova:
Cordova CLI : 9.0.0 (cordova-lib@9.0.1) Cordova Platforms : android 8.1.0, browser 6.0.0, ios 5.0.1 Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.1, (and 11 other plugins)
Utility:
cordova-res : not installed native-run (update available: 1.0.0) : 0.2.8
System:
Android SDK Tools : 26.1.1 (/Users/merwanropers/Library/Android/sdk) ios-deploy : 1.9.4 NodeJS : v14.0.0 (/usr/local/Cellar/node/14.0.0/bin/node) npm : 6.14.4 OS : macOS Catalina Xcode : Xcode 11.4 Build version 11E146_
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7
(Sorry for any mistake, English is not my official language.)
I have a solution for android 10.
Add to your
<edit-config>
in the config.xml file:<application android:requestLegacyExternalStorage="true" />
Make sure that the build.gradle in the /platforms/android/ folder has the variables configured for sdk api level 29: defaultBuildToolsVersion = “29.0.0” defaultMinSdkVersion = 19 defaultTargetSdkVersion = 29 defaultCompileSdkVersion = 29
Finally, make sure your build is running at sdk’s api level 29.
The error happens due to a lack of android permission on the external storage folder (android 10 updates).
Links that I used as a basis to develop the solution https://medium.com/@sriramaripirala/android-10-open-failed-eacces-permission-denied-da8b630a89df https://github.com/geosparks/geospark-cordova-example/issues/3#issuecomment-558510384
Hello @Merwan1010
I did the same code (https://github.com/apache/cordova-plugin-media/issues/277#issuecomment-624503732) in My Application But Audio file is not playing
mp3file.release(); // Don't forget to release ! Otherwise the audio won't play on Android after a certain amount of media created.
But I just debugged the code for the resolve the issue at that time I Just comment that
mp3file.release()
and audio file is playing fine so I am confused as per plugin it’s must release the file in Android but it’s working fine after comment that particular line So can you please guide me for thisThanks!