Playing multiple files in MediaPlayer one after other In android

前端 未结 3 2030
情歌与酒
情歌与酒 2020-12-16 09:01

I am having Problem in playing multiple mp3 files in MediaPlayer for android ...It plays all files together and creates mess.I want the solution that it just play each file

3条回答
  •  没有蜡笔的小新
    2020-12-16 09:24

    I did this by following code:

    private ArrayList mPlayerList = new ArrayList();
    public void playSound4FileList(ArrayList fileList) 
    {
        mPlayerList.clear();
        for (String fileName : fileList)
        {
            try {
                MediaPlayer mPlayerT = new MediaPlayer();
    
                AssetFileDescriptor descriptor = context.getAssets().openFd(fileName);
                mPlayerT.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength());
                descriptor.close();
    
                mPlayerT.prepare();
                mPlayerT.setVolume(1f, 1f);
                mPlayerT.setLooping(false);
    
                mPlayerList.add(mPlayerT);
    
            } catch (Exception e) {
            }
    
        }
        for (int i=0; i

提交回复
热议问题