[ 
https://issues.apache.org/jira/browse/CB-8020?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Aaron Ruß updated CB-8020:
--------------------------
    Description: 
On Android, if a Media object is only used for playing a sound, i.e. not for 
recording, then, on releasing the media object, an error is logged to the 
LogCat console, complaining about a failed attempt to rename the temporary file 
(that is used for recording audio).


{panel:title=Example LogCat output (after releasing the Media object):}
11-14 13:57:14.138: V/MediaPlayer(29175): destructor
11-14 13:57:14.138: V/MediaPlayer(29175): disconnect
11-14 13:57:14.138: D/AudioPlayer(29175): renaming 
/storage/emulated/0/tmprecording.3gp to 
/android_asset/www/audio/beep-notification.mp3
{color:red}11-14 13:57:14.138: E/AudioPlayer(29175): FAILED renaming 
/storage/emulated/0/tmprecording.3gp to 
/android_asset/www/audio/beep-notification.mp3{color}
{panel}



Solution:
in the AudioPlayer class, do not create the MediaRecorder (for audio recording) 
on object creation (i.e. in the AudioPlayer's constructor), but instead create 
it lazily, only if/when the AudioPlayer is used for recording audio (i.e. in 
method {{startRecording(String)}}).
Example solution see:
https://github.com/mmig/cordova-plugin-media/commit/66ac88689cb092179cdc3eda3bd64b1d8616077e



NOTE:
In addition to manually testing, that the proposed changes (see GitHub link 
above) did not brake recording, I also did run the unit tests from plugin 
{{org.apache.cordova.media.tests}} successfully
(on a Samsung Note 10 device with Android 4.4.2)


NOTE 2:
this is the same issue as described in 
[CB-3800|https://issues.apache.org/jira/browse/CB-3800] and 
[CB-3835|https://issues.apache.org/jira/browse/CB-3835] 
...in CB-3835 David Mihalcik already provided the solution ... but it was not 
accepted ... yet (??)

NOTE 3:
the code in AudioPlayer suggests, that lazy-loading of the recorder was planned 
or had been implemented at some point and then was changed (for whatever 
reason).
See for example methods {{destroy()}}, {{stopRecording}}, and 
{{getDuration()}}: in these methods it is assumed, that the {{recorder}} field 
is {{null}}, if the AudioPlayer objec _is not_ used for recording (and is not 
{{null}} if it _is_ used for recording).

  was:
On Android, if a Media object is only used for playing a sound, i.e. not for 
recording, then, on releasing the media object, an error is logged to the 
LogCat console, complaining about a failed attempt to rename the temporary file 
(that is used for recording audio).


{panel:title=Example LogCat output (after releasing the Media object):}
11-14 13:57:14.138: V/MediaPlayer(29175): destructor
11-14 13:57:14.138: V/MediaPlayer(29175): disconnect
11-14 13:57:14.138: D/AudioPlayer(29175): renaming 
/storage/emulated/0/tmprecording.3gp to 
/android_asset/www/audio/beep-notification.mp3
{color:red}11-14 13:57:14.138: E/AudioPlayer(29175): FAILED renaming 
/storage/emulated/0/tmprecording.3gp to 
/android_asset/www/audio/beep-notification.mp3{color}
{panel}



Solution:
in the AudioPlayer class, do not create the MediaRecorder (for audio recording) 
on object creation (i.e. in the AudioPlayer's constructor), but instead create 
it lazily, only if/when the AudioPlayer is used for recording audio (i.e. in 
method {{startRecording(String)}}).
Example solution see:
https://github.com/mmig/cordova-plugin-media/commit/66ac88689cb092179cdc3eda3bd64b1d8616077e



NOTE:
In addition to manually testing, that the proposed changes (see GitHub link 
above) did not brake recording, I also did run the unit tests from plugin 
{{org.apache.cordova.media.tests}} successfully
(on a Samsung Note 10 device with Android 4.4.2)


NOTE 2:
this is the same issue as described in 
[CB-3800|https://issues.apache.org/jira/browse/CB-3800] and 
[CB-3835|https://issues.apache.org/jira/browse/CB-3835] 
...in CB-3835 David Mihalcik already provided the solution ... but it was not 
accepted ... yet (??)

NOTE 3:
the code in AudioPlayer suggests, that lazy-loading of the recorder was planned 
or had been implemented at some point and then was changed (for whatever 
reason).
See for example methods `destroy()`, `stopRecording`, and `getDuration()`: in 
these methods it is assumed, that the `recorder` field is `null`, if the 
AudioPlayer objec _is not_ used for recording (and is not `null` if it _is_ 
used for recording).


> avoid error message in console for failed renaming of recording-file (if 
> Media object was only used for playing)
> ----------------------------------------------------------------------------------------------------------------
>
>                 Key: CB-8020
>                 URL: https://issues.apache.org/jira/browse/CB-8020
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android, Plugin Media
>            Reporter: Aaron Ruß
>            Priority: Minor
>   Original Estimate: 10m
>  Remaining Estimate: 10m
>
> On Android, if a Media object is only used for playing a sound, i.e. not for 
> recording, then, on releasing the media object, an error is logged to the 
> LogCat console, complaining about a failed attempt to rename the temporary 
> file (that is used for recording audio).
> {panel:title=Example LogCat output (after releasing the Media object):}
> 11-14 13:57:14.138: V/MediaPlayer(29175): destructor
> 11-14 13:57:14.138: V/MediaPlayer(29175): disconnect
> 11-14 13:57:14.138: D/AudioPlayer(29175): renaming 
> /storage/emulated/0/tmprecording.3gp to 
> /android_asset/www/audio/beep-notification.mp3
> {color:red}11-14 13:57:14.138: E/AudioPlayer(29175): FAILED renaming 
> /storage/emulated/0/tmprecording.3gp to 
> /android_asset/www/audio/beep-notification.mp3{color}
> {panel}
> Solution:
> in the AudioPlayer class, do not create the MediaRecorder (for audio 
> recording) on object creation (i.e. in the AudioPlayer's constructor), but 
> instead create it lazily, only if/when the AudioPlayer is used for recording 
> audio (i.e. in method {{startRecording(String)}}).
> Example solution see:
> https://github.com/mmig/cordova-plugin-media/commit/66ac88689cb092179cdc3eda3bd64b1d8616077e
> NOTE:
> In addition to manually testing, that the proposed changes (see GitHub link 
> above) did not brake recording, I also did run the unit tests from plugin 
> {{org.apache.cordova.media.tests}} successfully
> (on a Samsung Note 10 device with Android 4.4.2)
> NOTE 2:
> this is the same issue as described in 
> [CB-3800|https://issues.apache.org/jira/browse/CB-3800] and 
> [CB-3835|https://issues.apache.org/jira/browse/CB-3835] 
> ...in CB-3835 David Mihalcik already provided the solution ... but it was not 
> accepted ... yet (??)
> NOTE 3:
> the code in AudioPlayer suggests, that lazy-loading of the recorder was 
> planned or had been implemented at some point and then was changed (for 
> whatever reason).
> See for example methods {{destroy()}}, {{stopRecording}}, and 
> {{getDuration()}}: in these methods it is assumed, that the {{recorder}} 
> field is {{null}}, if the AudioPlayer objec _is not_ used for recording (and 
> is not {{null}} if it _is_ used for recording).



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to