资产经理,OpenFd? [英] Asset Manager, OpenFd?

查看:73
本文介绍了资产经理,OpenFd?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的资产文件夹中有一个文件,我想通过以下方式进行访问:

I have a file in my assets folder I wish to access, I do so by:

AssetFileDescriptor fileSound = am.openFd("myfilepathetc/mymp3.mp3");

但是我得到了错误:

This file can not be opened as a file descriptor; it is probably compressed

经过一番谷歌搜索之后,似乎我需要向文件中添加扩展名,例如.mp3,因为Android会压缩资产文件夹中的内容,除非其格式已被压缩,唯一的问题是,我的文件已经是mp3而且它仍然无法打开.

After some googling it appears that I need to add an extension to my file, such as .mp3 as Android compresses stuff in the assets folder unless its of a format already compressed, the only problem is, my file is already an mp3 and it still wont open.

是否有不妥协的方法?还是有人有更好的方法从资产访问mp3,请注意,由于我不想打扰,我不想从原始文件夹访问它.

Is there a way of uncompromising it? Or does anyone have a better way to access an mp3 from assets, please note I do not want to access it from the raw folder for reasons i wont bother going into.

推荐答案

为什么不使用它:

private void playAudioSound() {
    try {
        AssetFileDescriptor afd = context.getAssets().openFd("sounds/jad0005a.wav");
        MediaPlayer player = new MediaPlayer();
        player.setDataSource(afd.getFileDescriptor());
        player.prepare();
        player.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

这篇关于资产经理,OpenFd?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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