【问题标题】:Join two MP3s in Android在 Android 中加入两个 MP3
【发布时间】:2014-10-14 13:41:47
【问题描述】:

我看了几页,但我找到了问题的解决方案,想将两个mp3曲目合二为一,但当时他写输出(juntos4.mp3,只是歌曲,有人可以帮帮我吗?

“我的”代码...

                FileInputStream fis1 = new FileInputStream("/sdcard/1408586436107.mp3");  // first source file
                FileInputStream fis2 = new FileInputStream("/sdcard/1408586281745.mp3");//second source file
                SequenceInputStream sis = new SequenceInputStream(fis1, fis2);
                FileOutputStream fos = new FileOutputStream("/sdcard/juntos4.mp3");//destinationfile

                int temp;

                try {
                    while ((temp = sis.read())!= -1){

                        fos.write(temp);

                    }

                    fis1.close();
                    fis2.close();
                    sis.close();
                    fos.close();

                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


        }

【问题讨论】:

  • 你到底想要什么?
  • 将两个文件 mp3(音乐)合并到一个唯一的文件中,包含两个 mp3 文件...
  • 你现在得到什么输出?
  • @DiogoOdelli 检查答案
  • 只是第一首曲目...FileInputStream fis1 = new FileInputStream("/sdcard/1408586436107.mp3"); // 第一个源文件...

标签: java android join mp3 output


【解决方案1】:

创建文件而不是目录!

newFile.createNewFile();


FileInputStream fistream1 = new FileInputStream(newFile1 );  // first source file
    FileInputStream fistream2= new FileInputStream(newFile2 );//second source file
    Vector<FileInputStream> v = new Vector<FileInputStream>();
    v.add(fistream1);
    v.add(fistream2);
    SequenceInputStream sistream = new SequenceInputStream(fistream1, fistream2);

    if(!newFile.exists()){
        newFile.createNewFile();
        FileOutputStream fostream=new FileOutputStream(newFile, true);
        int temp;

        while( ( temp = sistream.read() ) != -1)
        {
            System.out.print( (char) temp ); // to print at DOS prompt
            fostream.write((byte)temp);   // to write to file
        }

        fostream.close();
        sistream.close();
        fistream1.close();
        fistream2.close();
    }

【讨论】:

  • 第三,当我使用双参数构造函数时,sequenceinputstream 似乎不适用于我,而是使用带有枚举器的构造函数。 stackoverflow.com/questions/19489316/…是的,你说的很对!!
  • 嘿,我当时才意识到这是从我的回答中复制/粘贴的,哈哈^^
  • 祝你好运!我很高兴我在那里制作了工作代码^^
  • @MartinFrank 我在无法找到我存储的代码之前使用过你的代码。所以我只是提供了 r 代码。对此感到抱歉。我给你一个赞成票
  • 没关系,没关系,这不是我的代码本身......我很高兴我能帮助别人,现在和现在^^
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-22
  • 2011-10-07
  • 2012-09-03
  • 2012-04-26
相关资源
最近更新 更多