[AC-1941] Android fails to play sound from internal storage
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2012-10-05T23:27:51.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | n/a |
Reporter | Johan Lundin |
Assignee | Varun Joshi |
Created | 2012-09-06T16:44:33.000+0000 |
Updated | 2016-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 {
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
Johan, Just wanted to know the update on this. Did you get time to look into the link I provided above? Thanks, Varun
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
Fixed as per above comment.