我正在使用mp4解析器来附加视频。我的问题是我无法追加视频。我收到了BufferUnderFlow Exception等错误。谁能告诉我哪里可能犯了错误?
这是我的代码:
public class MainActivity extends Activity
{
Button b1;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener()
{
@SuppressWarnings("resource")
@Override
public void onClick(View v)
{
try
{
String f1 = Environment.getExternalStorageDirectory()+ "/wish_by_video.mp4";
String f2 = Environment.getExternalStorageDirectory() + "/wish_by_video.mp4";
String f3 = Environment.getExternalStorageDirectory() + "/wish_by_video.mp4";
Movie[] inMovies = new Movie[]{
MovieCreator.build(new FileInputStream(f1).getChannel()),
MovieCreator.build(new FileInputStream(f2).getChannel()),
MovieCreator.build(new FileInputStream(f3).getChannel())
};
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[3])));
}
IsoFile out = new DefaultMp4Builder().build(result);
@SuppressWarnings("resource")
FileChannel fc = new RandomAccessFile(String.format(Environment.getExternalStorageDirectory()+"output.mp4"), "rw").getChannel();
fc.position(0);
out.getBox(fc);
fc.close();
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
}