【问题标题】:how to get information of music files from assets folders?如何从资产文件夹中获取音乐文件的信息?
【发布时间】:2018-10-09 06:12:18
【问题描述】:

我有以下代码可以读取我的手机并获取手机中音乐文件的信息

String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
String[] projectionSongs = {MediaStore.Audio.Media._ID, MediaStore.Audio.Media.ARTIST,
            MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.ALBUM,
            MediaStore.Audio.Media.DISPLAY_NAME, MediaStore.Audio.Media.DURATION};
Cursor cursor = mContext.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projectionSongs,
                    selection, null, null);

现在我想从资产文件夹本身获取相同的信息。 我在努力

Uri uri = Uri.parse("file:///assets/");
Cursor cursor = mContext.getContentResolver().query(uri, projectionSongs,
                    selection, null, null);

但它不起作用。游标中没有信息。但是我在 assets 文件夹中有一些 mp3 文件。

【问题讨论】:

    标签: java android android-music-player


    【解决方案1】:
     public void playBeep() {
        try {
            if (m.isPlaying()) {
                m.stop();
                m.release();
                m = new MediaPlayer();
            }
    
            AssetFileDescriptor descriptor = getAssets().openFd("your_audio_file_name.mp3");
            m.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());
            descriptor.close();
    
            m.prepare();
            m.setVolume(1f, 1f);
            m.setLooping(true);
            m.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    

    希望这会对你有所帮助。谢谢

    【讨论】:

      猜你喜欢
      • 2011-07-19
      • 1970-01-01
      • 2014-03-10
      • 1970-01-01
      • 2021-10-24
      • 1970-01-01
      • 1970-01-01
      • 2017-01-16
      • 1970-01-01
      相关资源
      最近更新 更多