Android的 - 问题的演奏从资产文件夹中的声音 [英] Android - Problem playing sounds from assets folder

查看:194
本文介绍了Android的 - 问题的演奏从资产文件夹中的声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已存储的资产文件夹5 mp3文件。这些文件都是25 KB。

我使用加载文件:

i have 5 mp3 files stored on the assets folder. The files are all 25 KB.
I load the files using:

manager = context.getAssets();
this.inputStream = manager.openFd(fileName).createInputStream();

每当我尝试播放文件时,声音都搞砸像他们混什么的。
我zipalign处理应用程序已经,但没有结果。

ANNY帮助这个问题?在此先感谢

Whenever i try to play the files, the sounds are all messed up like they were mixed or something. I've zipaligned the app already but with no results.
anny help about this issue? Thanks in advance

推荐答案

经过一番研究,我发现自己awnser。问题是我使用下面的方法来设置MediaPlayer的数据源:

After some research i've found the awnser myself. the problem was i was using the following method to set the MediaPlayer's datasource:

inputStream = manager.openFd(fileName).createInputStream();    
player.setDataSource(inputStream.getFD());

至极仅仅是的setDataSource(FD,0,0x7ffffffffffffffL)的调用; ,传递min的偏移而这个任意长度,导致声音要播放所有混合。

当使用以下code一切工作得很好:

Wich is just a call to setDataSource(fd, 0, 0x7ffffffffffffffL);, passing the min offset and this arbitrary length, causing the sounds to be played all mixed.
When using the following code everything worked fine:

AssetFileDescriptor descriptor = manager.openFd(fileName);
long start = descriptor.getStartOffset();
long end = descriptor.getLength();
player.setDataSource(descriptor.getFileDescriptor(), start,end);

这篇关于Android的 - 问题的演奏从资产文件夹中的声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆