{ "id": "131434", "key": "AC-897", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "12217", "key": "AC", "name": "Appcelerator - INBOX", "projectCategory": { "id": "10000", "description": "", "name": "Customer Service" } }, "resolution": { "id": "3", "description": "The problem is a duplicate of an existing issue.", "name": "Duplicate" }, "resolutiondate": "2014-06-09T17:38:27.000+0000", "created": "2014-06-09T17:11:28.000+0000", "labels": [], "versions": [], "issuelinks": [ { "id": "38218", "type": { "id": "10002", "name": "Duplicate", "inward": "is duplicated by", "outward": "duplicates" }, "outwardIssue": { "id": "124176", "key": "TIMOB-16134", "fields": { "summary": "Android: MediaPlayer on KitKat displays console error about subtitle controller", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "priority": { "name": "High", "id": "2" }, "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false } } } } ], "assignee": { "name": "ragrawal", "key": "ragrawal", "displayName": "Ritu Agrawal", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2016-03-08T07:37:12.000+0000", "status": { "description": "A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.", "name": "Resolved", "id": "5", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "14548", "name": "Titanium SDK & CLI", "description": "Please enter tickets related to the MobileSDK here." } ], "description": "h2. Problem\r\n\r\nAn app that creates a Titanium.Media.Sound object and calls the the play method on it can cause a java.lang.IllegalStateException exception to occur when the main window closes and the app exits. The exception seems to rarely occur in apps that are light on resources, but an app using a lot of memory/resources might crash 1 out of 4 or 5 times it is executed. Output during the crash is:\r\n\r\n{code:lang=none|title=console}\r\n05-10 17:47:20.445: W/dalvikvm(2004): threadid=28: thread exiting with uncaught exception (group=0xb1a18ba8)\r\n05-10 17:47:20.475: E/TiApplication(2004): (Timer-28) [46093,46093] Sending event: exception on thread: Timer-28 msg:java.lang.IllegalStateException; Titanium 3.2.3,2014/04/22 10:17,b958a70\r\n05-10 17:47:20.475: E/TiApplication(2004): java.lang.IllegalStateException\r\n05-10 17:47:20.475: E/TiApplication(2004): \tat android.media.MediaPlayer.isPlaying(Native Method)\r\n05-10 17:47:20.475: E/TiApplication(2004): \tat ti.modules.titanium.media.TiSound$2.run(TiSound.java:516)\r\n05-10 17:47:20.475: E/TiApplication(2004): \tat java.util.Timer$TimerImpl.run(Timer.java:284)\r\n05-10 17:47:20.495: E/AndroidRuntime(2004): FATAL EXCEPTION: Timer-28\r\n05-10 17:47:20.495: E/AndroidRuntime(2004): Process: com.plezzus.magnoids, PID: 2004\r\n05-10 17:47:20.495: E/AndroidRuntime(2004): java.lang.IllegalStateException\r\n05-10 17:47:20.495: E/AndroidRuntime(2004): \tat android.media.MediaPlayer.isPlaying(Native Method)\r\n05-10 17:47:20.495: E/AndroidRuntime(2004): \tat ti.modules.titanium.media.TiSound$2.run(TiSound.java:516)\r\n05-10 17:47:20.495: E/AndroidRuntime(2004): \tat java.util.Timer$TimerImpl.run(Timer.java:284)\r\n{code}\r\n\r\nh2. Test case\r\n\r\nThe exception seems to be caused by a race condition that's hard to reproduce... I've located the source of the problem at the onDestroy() method at line 534 in TiSound.java as the cause of the error. To make a reliable test case, I patched TiSound.java by adding a delay after mp.release() at line 537. The delay makes it easier for the race condition to happen. I changed onDestroy at line 534 in TiSound.java to read:\r\n\r\n{code:lang=java}\r\n\tpublic void onDestroy()\r\n\t{\r\n\t\tif (mp != null) {\r\n\t\t\tmp.release();\r\n\t\t\tLog.d(TAG, \"begin delay\");\r\n\t\t\tfor (int i = 0; i < 1000000000; ++i) {} // delay-causing no-op loop to help race condition to occur\r\n\t\t\tLog.d(TAG, \"end delay\");\r\n\t\t\tmp = null;\r\n\t\t}\r\n\t\t// TitaniumMedia clears out the references after onDestroy.\r\n\t}\r\n{code}\r\n\r\nThe test case app.js is:\r\n\r\n{code:lang=javascript|title=app.js}\r\nvar win = Titanium.UI.createWindow({ \r\n title:'Sound Bug',\r\n fullscreen: true,\r\n exitOnClose: true \r\n});\r\nvar bell = Ti.Media.createSound({url: 'bell.mp3', preload: true, volume: 1});\r\nwin.addEventListener('open', function() {\r\n setTimeout(function() {\r\n\tbell.play();\r\n\tsetTimeout(function() {\r\n\t win.close();\r\n\t}, 100);\r\n }, 1000);\r\n});\r\nwin.open();\r\n{code}\r\n\r\nThe test might have to be run multiple times to produce the exception. Also, bell.mp3 is attached.\r\n\r\nh2. Logs\r\n\r\nOutput of test case:\r\n\r\n{code:lang=none|title=console}\r\n[DEBUG] TiSound: (main) [1985,1985] begin delay\r\n[WARN] dalvikvm: threadid=14: thread exiting with uncaught exception (group=0xb1a77ba8)\r\n[ERROR] TiApplication: (Timer-0) [870,2855] Sending event: exception on thread: Timer-0 msg:java.lang.IllegalStateException; Titanium 3.2.3,2014/06/09 10:38,b958a70\r\n[ERROR] TiApplication: java.lang.IllegalStateException\r\n[ERROR] TiApplication: \tat android.media.MediaPlayer.isPlaying(Native Method)\r\n[ERROR] TiApplication: \tat ti.modules.titanium.media.TiSound$2.run(TiSound.java:516)\r\n[ERROR] TiApplication: \tat java.util.Timer$TimerImpl.run(Timer.java:284)\r\n[INFO] Process: Sending signal. PID: 1938 SIG: 9\r\n{code}\r\n\r\nh2. Discussions\r\n\r\nQ/A Link: http://developer.appcelerator.com/question/174077/using-sound-objects-in-android-app-causes-java-exception-and-crash-on-app-exit\r\n\r\nCurrent workaround: I've modifed the onDestroy() method in TiSound.java to read:\r\n\r\n{code:lang=java}\r\n\tpublic void onDestroy()\r\n\t{\r\n\t\tstopProgressTimer(); // stop the timer so it won't cause exception\r\n\t\tif (mp != null) {\r\n\t\t\tmp.release();\r\n\t\t\tmp = null;\r\n\t\t}\r\n\t\t// TitaniumMedia clears out the references after onDestroy.\r\n\t}\r\n{code}\r\n", "attachment": [ { "id": "48756", "filename": "bell.mp3", "author": { "name": "dpsenick", "key": "dpsenick", "displayName": "David Psenicka", "active": true, "timeZone": "America/Chicago" }, "created": "2014-06-09T17:11:28.000+0000", "size": 39287, "mimeType": "audio/mpeg" } ], "flagged": false, "summary": "Android: Creating/playing Sound objects can cause app to crash on exit", "creator": { "name": "dpsenick", "key": "dpsenick", "displayName": "David Psenicka", "active": true, "timeZone": "America/Chicago" }, "subtasks": [], "reporter": { "name": "dpsenick", "key": "dpsenick", "displayName": "David Psenicka", "active": true, "timeZone": "America/Chicago" }, "environment": "Titanium SDK version: Titanium 3.2.3 (2014/04/22 10:17 b958a70)\r\nJavascript Engine: V8\r\nPlatform & version: Android 4.4.2, Android 4.1.2\r\nDevice Details: Android emulator (ARM CPU, API version 4.4.2) and physical device (Droid Bionic, API versino 4.1.2)\r\nHost Operating System: Ubuntu 13.10\r\nTitanium Studio version: using the CLI", "comment": { "comments": [ { "id": "308044", "author": { "name": "ragrawal", "key": "ragrawal", "displayName": "Ritu Agrawal", "active": true, "timeZone": "America/Los_Angeles" }, "body": "David - Excellent description and great writeup. Much appreciated. Thanks for the workaround.\r\n\r\nHowever, this is a duplicate of TIMOB-16134. Please watch TIMOB-16134 for latest updates.", "updateAuthor": { "name": "ragrawal", "key": "ragrawal", "displayName": "Ritu Agrawal", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2014-06-09T17:35:31.000+0000", "updated": "2014-06-09T17:35:31.000+0000" } ], "maxResults": 1, "total": 1, "startAt": 0 } } }