Titanium JIRA Archive
Appcelerator Community (AC)

[AC-1941] Android fails to play sound from internal storage

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionFixed
Resolution Date2012-10-05T23:27:51.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterJohan Lundin
AssigneeVarun Joshi
Created2012-09-06T16:44:33.000+0000
Updated2016-03-08T07:40:52.000+0000

Description

Same problem as TC-1228 is for video but this is for sound. Permissioning on Android prevents media player to play sound file through url and has to play through file descriptor. if (URLUtil.isAssetUrl(url)) { Context context = TiApplication.getInstance(); String path = url.substring(TiConvert.ASSET_URL.length()); // Needed to handle native path urls path = path.replace("Resources//", "Resources/"); AssetFileDescriptor afd = null; try { afd = context.getAssets().openFd(path); // Why mp.setDataSource(afd) doesn't work is a problem for another day. // http://groups.google.com/group/android-developers/browse_thread/thread/225c4c150be92416 mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); } catch (IOException e) { Log.e(LCAT, "Error setting file descriptor: ", e); } finally { if (afd != null) { afd.close(); } } } else { should be if (URLUtil.isAssetUrl(url)) { Context context = TiApplication.getInstance(); String path = url.substring(TiConvert.ASSET_URL.length()); // Needed to handle native path urls path = path.replace("Resources//", "Resources/"); AssetFileDescriptor afd = null; try { afd = context.getAssets().openFd(path); // Why mp.setDataSource(afd) doesn't work is a problem for another day. // http://groups.google.com/group/android-developers/browse_thread/thread/225c4c150be92416 mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); } catch (IOException e) { Log.e(LCAT, "Error setting file descriptor: ", e); } finally { if (afd != null) { afd.close(); } } } else if(url.toString().startsWith(("file://"))) { // Loading from internal storage using fil desc for media player to be able to read FileInputStream fis = new FileInputStream(url.toString().substring("file://".length())); mp.setDataSource(fis.getFD()); } else {

Comments

  1. Varun Joshi 2012-09-11

    Hi Johan, I see that you have provided a solution for this issue. I would suggest you to follow these guidelines (https://wiki.appcelerator.org/display/guides/How+to+Contribute+Code) and make a pull request for the platform to look at so they can merge if its correct. Thanks, Varun
  2. Varun Joshi 2012-09-24

    Johan, Just wanted to know the update on this. Did you get time to look into the link I provided above? Thanks, Varun
  3. Johan Lundin 2012-09-25

    Hi Varun, yes but I don't have the time for it. I solved all my submitted jiras by creating a module with the fixes in it. Feel free to close the jira if you don't think the bug is serious enough. Regards, Johan
  4. Varun Joshi 2012-10-05

    Fixed as per above comment.

JSON Source