klaw-PLS opened a new issue #325:
URL: https://github.com/apache/cordova-plugin-media/issues/325
# Bug Report
## Problem
When attempting to play an audio file using `media.play()` that was recorded
with `media.startRecord()` it would throw a media error code 1 with no error
message.
### What is expected to happen?
The media file will play.
### What does actually happen?
The media file does not play and a media error code 1 is be reported.
## Information
<!-- Include all relevant information that might help understand and
reproduce the problem -->
I am using the latest dev version of the plugin (PR #317) to attempt to
comply with the requirements of API 30 and the Google Play Store. As you can
see in the example program below, I am only using a simple file name as the
source for both the record and play APIs.
When debugging through the plugin code, I was able to determine that when a
simple file name is provided for the `media.startRecord()` API a file path is
eventually generated in the `createAudioFilePath()` method using either
`getExternalFilesDir()` or `getCacheDir()`. In my emulator, it creates a
temporary file path like the following:
`/storage/emulated/0/Android/data/com.<org>.<appName>/files/tmprecording-###.3gp`.
(The logic for creating this temporary file path was updated in PR #317.)
However, when a simple file name is provided to the `media.play()` API, a
different file path is created instead. The logic is located in the
`loadAudioFile()` method, but for my situation it eventually calls the
`Environemt.getExternalStorageDirectory()` to create the file path. I do not
have the file path on hand at the moment, but it does not match the file path
created via the `createAudioFilePath()` method. (I am just now realizing that
PR #317 specifically was trying to remove `getExternalStorageDirectory()` and
perhaps this use was overlooked?)
To work around this issue, I just updated line 709 of `AudioPlayer.java` to
read the following instead:
```
//this.player.setDataSource(Environment.getExternalStorageDirectory().getPath()
+ "/" + file);
this.player.setDataSource(createAudioFilePath(file));
```
Using this workaround, I no longer have an error code thrown, and when I
load my app onto an actual device, I am able to record and playback audio just
fine. (For some reason, recording on my emulator does not pick up my
microphone input.) My main concern with this approach is that, if I am
understanding it correctly, the `media.play()` API is supposed to be able to
accept a much larger range of audio sources compared to `media.startRecord()`.
This leads me to be concerned that reusing code from `media.startRecord()` will
somehow restrict media sources that should otherwise be acceptable.
### Command or Code
<!-- What command or code is needed to reproduce the problem? -->
Here is a snippet from my test program. The following functions are
connected to the onclick event of buttons on my screen:
```
function recordAudioButtonPressed() {
var platform = device.platform;
var mediaType = platform === "Android" ? "aac" : "m4a";
var src = "testRecording." + mediaType;
var mediaRec = new Media(
src,
function () {},
function (err) {
navigator.notification.alert(
"An error occurred while recording audio: " + err.message,
function () { },
"Error",
"Ok");
});
mediaRec.startRecord();
setTimeout(function () {
mediaRec.stopRecord();
mediaRec.release();
}, 3000);
}
function playAudioButtonPressed() {
var platform = device.platform;
var mediaType = platform === "Android" ? "aac" : "m4a";
var src = "testRecording." + mediaType;
var mediaPlay = new Media(
src,
function () {
mediaPlay.release();
},
function (err) {
navigator.notification.alert(
"An error occurred while playing audio.",
function () { },
"Error",
"Ok");
});
mediaPlay.play();
}
```
### Environment, Platform, Device
<!-- In what environment, on what platform or on which device are you
experiencing the issue? -->
I am encountering this issue on Android, using emulated devices running API
29 and 30, as well as a Samsung Galaxy S9+ running Android 10 (which should be
API 29 iirc).
### Version information
<!--
What are relevant versions you are using?
For example:
Cordova: Cordova CLI, Cordova Platforms, Cordova Plugins
Other Frameworks: Ionic Framework and CLI version
Operating System, Android Studio, Xcode etc.
-->
10.0.0 ([email protected])
Installed platforms:
android 9.1.0
Android SDK Build-Tools installed:
32.0.0
32.0.0-rc1
31.0.0
30.0.3
SDK Platforms:
Android 11.0 Installed
Android 10.0 Partially Installed
Android 9.0 Partially Installed
$ cordova plugin list
cordova-plugin-battery-status 2.0.3 "Battery"
cordova-plugin-camera 5.0.3 "Camera"
cordova-plugin-contacts 3.0.1 "Contacts"
cordova-plugin-device-motion 2.0.1 "Device Motion"
cordova-plugin-device-orientation 2.0.1 "Device Orientation"
cordova-plugin-device 2.0.3 "Device"
cordova-plugin-dialogs 2.0.2 "Notification"
cordova-plugin-file-transfer 2.0.0-dev "File Transfer"
cordova-plugin-file 6.0.2 "File"
cordova-plugin-geolocation 4.1.0 "Geolocation"
cordova-plugin-globalization 1.11.0 "Globalization"
cordova-plugin-inappbrowser 5.0.1-dev "InAppBrowser"
cordova-plugin-media-capture 3.0.3 "Capture"
cordova-plugin-media 5.0.4-dev "Media"
cordova-plugin-nativestorage 2.3.2 "NativeStorage"
cordova-plugin-network-information 3.0.0 "Network Information"
cordova-plugin-screen-orientation 3.0.2 "Screen Orientation"
cordova-plugin-splashscreen 6.0.0 "Splashscreen"
cordova-plugin-statusbar 3.0.0-dev "StatusBar"
cordova-plugin-vibration 3.1.1 "Vibration"
cordova-plugin-whitelist 1.3.5 "Whitelist"
cordova-sms-plugin 1.0.1 "Cordova SMS Plugin"
es6-promise-plugin 4.2.2 "Promise"
phonegap-plugin-barcodescanner 8.1.0 "BarcodeScanner"
I am developing on Windows 10, and running my emulators on the same machine.
Android Studio Arctic Fox | 2020.3.1 Patch 3
Build #AI-203.7717.56.2031.7784292, built on September 30, 2021
Runtime version: 11.0.10+0-b96-7249189 amd64
VM: OpenJDK 64-Bit Server VM by Oracle Corporation
Windows 10 10.0
GC: G1 Young Generation, G1 Old Generation
Memory: 1280M
Cores: 12
Registry: external.system.auto.import.disabled=true
Non-Bundled Plugins: org.jetbrains.kotlin, org.intellij.plugins.markdown
## Checklist
<!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
- [x] I searched for existing GitHub issues
- [ ] I updated all Cordova tooling to most recent version
- [x] I included all the necessary information above
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]