附加视频无法正常使用 - Android

时间:2013-11-03 14:22:50

标签: android video append mp4parser

我正在使用Sebastian Annies example为mp4parser添加3个视频。结果应该是一个视频同时播放所有三个视频。但是,我得到一个播放最后一次视频三次的视频。这是我的代码......

            //    int i = number of videos....
      try {         
        String[] f = new String[i];

        for (int count = 0; count < i; count++) {
            f[count] = "/sdcard/vid" + i + ".mp4";
        }

        Movie[] inMovies = new Movie[i];

        for (int count = 0; count < i; count++) {
            inMovies[count] = MovieCreator.build(f[count]);
        }

        List<Track> videoTracks = new LinkedList<Track>();
        List<Track> audioTracks = new LinkedList<Track>();

        for (Movie m : inMovies) {
            for (Track t : m.getTracks()) {
                if (t.getHandler().equals("soun")) {
                    audioTracks.add(t);
                }
                if (t.getHandler().equals("vide")) {
                    videoTracks.add(t);
                }
            }
        }

        Movie result = new Movie();

        if (audioTracks.size() > 0) {
            result.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));
        }
        if (videoTracks.size() > 0) {
            result.addTrack(new AppendTrack(videoTracks.toArray(new Track[videoTracks.size()])));
        }

        Container out = new DefaultMp4Builder().build(result);

        FileChannel fc = new RandomAccessFile(String.format
                ("/sdcard/output.mp4"),
                "rw").getChannel();
        out.writeContainer(fc);
        fc.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    VideoView v = (VideoView) findViewById(R.id.videoView1);
    //      v.setVideoPath("/sdcard/aaa" + i + ".mp4");
    v.setVideoPath("/sdcard/output.mp4");
    v.setMediaController(new MediaController(this));
    v.start();

我不知道为什么它没有做它应该做的事情。请帮我。感谢

1 个答案:

答案 0 :(得分:2)

您的问题是您使用相同的文件填充输入文件名:

for (int count = 0; count < i; count++) {
        f[count] = "/sdcard/vid" + i + ".mp4";
}

应该是

for (int count = 0; count < i; count++) {
        f[count] = "/sdcard/vid" + count + ".mp4";
    }

为了便于阅读,您最好使i成为循环变量,并使count为文件数。