Return-Path: X-Original-To: apmail-incubator-callback-dev-archive@minotaur.apache.org Delivered-To: apmail-incubator-callback-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1D466DC9F for ; Tue, 9 Oct 2012 17:54:03 +0000 (UTC) Received: (qmail 14791 invoked by uid 500); 9 Oct 2012 17:54:02 -0000 Delivered-To: apmail-incubator-callback-dev-archive@incubator.apache.org Received: (qmail 14714 invoked by uid 500); 9 Oct 2012 17:54:02 -0000 Mailing-List: contact callback-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@incubator.apache.org Delivered-To: mailing list callback-dev@incubator.apache.org Received: (qmail 14699 invoked by uid 99); 9 Oct 2012 17:54:02 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Oct 2012 17:54:02 +0000 Date: Tue, 9 Oct 2012 17:54:02 +0000 (UTC) From: "Simon MacDonald (JIRA)" To: callback-dev@incubator.apache.org Message-ID: <1018345560.15759.1349805242856.JavaMail.jiratomcat@arcas> In-Reply-To: <1688393165.5298.1349545383870.JavaMail.jiratomcat@arcas> Subject: [jira] [Assigned] (CB-1599) successCallback not called after stopRecording, duplicate AudioPlayer objects created MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CB-1599?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Simon MacDonald reassigned CB-1599: ----------------------------------- Assignee: Simon MacDonald (was: Filip Maj) > successCallback not called after stopRecording, duplicate AudioPlayer objects created > ------------------------------------------------------------------------------------- > > Key: CB-1599 > URL: https://issues.apache.org/jira/browse/CB-1599 > Project: Apache Cordova > Issue Type: Bug > Components: CordovaJS > Affects Versions: 2.1.0 > Environment: Android 2.3? > Reporter: Bob Flavin > Assignee: Simon MacDonald > Fix For: 2.1.0 > > Attachments: AudioHandler.java > > > A successCallback is not called sometimes after stopRecording() is called. > The problem is that javascript cordova calls to 'new Media()' and 'mediaObj.startRecord() are dispatched by androidExec (prompt) to new threads on the java side and are not synchronized. Thus org.apache.cordova.AudioHandler.execute for action='create', calls new AudioPlayer(). Asynchronously, ...AudioHandler.execute for action='startAudioRecording' calls AudioHandler.startAudioRecording(), which gets a null from this.players.get(id) which causes the if statement to call new AudioRecorder which creates a second instance of AudioRecorder for that id. > public void startRecordingAudio(String id, String file) { > AudioPlayer audio = this.players.get(id); > if ( audio == null) { > audio = new AudioPlayer(this, id, file); > this.players.put(id, audio); > } > audio.startRecording(file); > } > One instance of AudioPlayer goes into STATE MEDIA_RUNNING the other remains in MEDIA_NONE. > When the javascript calls mediaObj.stopRecord() (and mediaObj.release()) it may get the instance of AudioPlayer that is in MEDIA_NONE. This prevents AudioPlayer.stopRecording() from calling this.recorder.stop() and this.setState(STATE.MEDIA_STOPPED) because that AudioPlayer instance is in STATE MEDIA_NONE. Thus AudioPlayer.setState doesn't call the handler.sendJavascript to call the javascript Media.onStatus method that would call the statusCallback and the successCallback. > I think that the AudioHandler should have a synchronized block that prevents 'create' and 'startRecordingAudio from running at the same time and that 'create' should use the same code that startRecodingAudio does: > AudioPlayer audio = this.players.get(id); > if ( audio == null) { > audio = new AudioPlayer(this, id, file); > this.players.put(id, audio); > } > to prevent creating a second AudioPlayer instance if the startRecordingAudio thread executes before the 'create' thread. > There may be other actions in AudioHandler.execute that need this synchronization as well. > One effect of this problem is that the javascript successCallback is never called (after stopRecord) -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira