1

Androidで2つのオーディオファイルを追加するにはどうすればよいですか。これを試しましたが、機能しません。plsは私にsolnを与えます。私はtsA.mp3とB.mp3であるsdcardからファイルを連結する必要があります。連結メソッド呼び出しをマージするとき、私はそれらの両方をC.mp3であるsdcardの単一ファイルとして欲しいです...。 ...。

File original= new File("/mnt/sdcard/A.mp3");
 File temp=new File("/mnt/sdcard/B.mp3");
        Log.i("...............",""+path);


        try {
            File outFile= new File("/mnt/sdcard/C.mp3 ");

            DataOutputStream out=new DataOutputStream(new BufferedOutputStream(new FileOutputStream(outFile)));





        //  FileOutputStream out=new FileOutputStream(outFile);

            //OutputStream out = new FileOutputStream(original,true);


            int m,n;
            m=(int) temp.length();
            n=(int) original.length();

             byte[] buf1 = new byte[m];
             byte[] buf2 = new byte[n];

             byte[] outBytes = new byte[m+n];


             DataInputStream dis1=new DataInputStream(  new BufferedInputStream(new FileInputStream(original)));
             DataInputStream dis2=new DataInputStream(  new BufferedInputStream(new FileInputStream(temp)));



             dis1.read(buf1, 0, m);
             dis1.close();

             dis2.readFully(buf2, 0, n);
             dis2.close();


             out.write(buf1);
             out.write(buf2);
            out.flush();


                //in.close();
                out.close();
                System.out.println("File copied.");


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

ファイルA.mp3、B.mp3をC.mp3...に結合する必要があります。

4

2 に答える 2

2

knowbody の回答に加えて、mp3 ファイル形式の仕様については、こちらこちらで詳細を参照できます。

2 つの mp3 ファイルを合成する際には、考慮すべきことがたくさんあります。控えめに言っても、同じプログラムで同じ設定で、または音声について話している場合は、同じマイクから取得し、同じ設定で設定する必要があるということです。

于 2013-02-26T12:22:44.780 に答える
-1
import java.io.*;
public class TwoFiles
{
    public static void Main(String args[]) throws IOException
    {
        FileInputStream fistream1 = new FileInputStream("C:\\Temp\\1.mp3");
        FileInputStream fistream2 = new FileInputStream("C:\\Temp\\2.mp3");
        SequenceInputStream sistream = new SequenceInputStream(fistream1, fistream2);
        FileOutputStream fostream = new FileOutputStream("C:\\Temp\\final.mp3");

    int temp;

    while( ( temp = sistream.read() ) != -1)
    {

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

明確であることを願っています

于 2013-02-26T12:17:17.510 に答える