- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用com.googlecode.mp4parser
库合并音频文件。我有一个外部音频mp3文件,该文件存储在raw
资源中。由于以下异常,此文件无法合并,以下是我的代码:
从原始文件夹读取文件:
InputStream is = context.getResources().openRawResource(R.raw.my_mp3_file);
OutputStream output = null;
try {
File file = new File(context.getFilesDir(), "silence.mp3");
if(!file.exists()) {
file.createNewFile();
}
output = new FileOutputStream(file);
byte[] buffer = new byte[4 * 1024]; // or other buffer size
int read;
while ((read = is.read(buffer)) != -1) {
output.write(buffer, 0, read);
}
output.flush();
output.close();
fileReference= file;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace(); // handle exception, define IOException and others
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(fileReference.exists()) {
Movie m = new MovieCreator().build(fileReference.getAbsolutePath());
}
Movie m
时,我的代码未能引发异常:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.coremedia.iso.boxes.MovieBox.getBoxes(java.lang.Class)' on a null object reference
最佳答案
经过大量研究,这是我的结论和解决方案
用于合并音频和视频的MP4Parser仅使用.m4a扩展名
String root = Environment.getExternalStorageDirectory().toString();
String audio = root + "/" + "tests.m4a";
String video = root + "/" + "output.mp4";
String output = root + "/" + "aud_vid.mp4";
mux(video, audio, output);
public boolean mux(String videoFile, String audioFile, String outputFile) {
Movie video;
try {
video = new MovieCreator().build(videoFile);
} catch (RuntimeException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
Movie audio;
try {
audio = new MovieCreator().build(audioFile);
} catch (IOException e) {
e.printStackTrace();
return false;
} catch (NullPointerException e) {
e.printStackTrace();
return false;
}
Track audioTrack = audio.getTracks().get(0);
video.addTrack(audioTrack);
Container out = new DefaultMp4Builder().build(video);
FileOutputStream fos;
try {
fos = new FileOutputStream(outputFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
}
BufferedWritableFileByteChannel byteBufferByteChannel = new BufferedWritableFileByteChannel(fos);
try {
out.writeContainer(byteBufferByteChannel);
byteBufferByteChannel.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
private static class BufferedWritableFileByteChannel implements WritableByteChannel {
private static final int BUFFER_CAPACITY = 1000000;
private boolean isOpen = true;
private final OutputStream outputStream;
private final ByteBuffer byteBuffer;
private final byte[] rawBuffer = new byte[BUFFER_CAPACITY];
private BufferedWritableFileByteChannel(OutputStream outputStream) {
this.outputStream = outputStream;
this.byteBuffer = ByteBuffer.wrap(rawBuffer);
}
@Override
public int write(ByteBuffer inputBuffer) throws IOException {
int inputBytes = inputBuffer.remaining();
if (inputBytes > byteBuffer.remaining()) {
dumpToFile();
byteBuffer.clear();
if (inputBytes > byteBuffer.remaining()) {
throw new BufferOverflowException();
}
}
byteBuffer.put(inputBuffer);
return inputBytes;
}
@Override
public boolean isOpen() {
return isOpen;
}
@Override
public void close() throws IOException {
dumpToFile();
isOpen = false;
}
private void dumpToFile() {
try {
outputStream.write(rawBuffer, 0, byteBuffer.position());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
关于android - com.googlecode.mp4parser无法获取mp3音频文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44649294/
我正在使用com.googlecode.mp4parser库合并音频文件。我有一个外部音频mp3文件,该文件存储在raw资源中。由于以下异常,此文件无法合并,以下是我的代码: 从原始文件夹读取文件:
本文整理了Java中com.googlecode.htmlcompressor.compressor.XmlCompressor类的一些代码示例,展示了XmlCompressor类的具体用法。这些代码
本文整理了Java中com.googlecode.htmlcompressor.compressor.YuiJavaScriptCompressor类的一些代码示例,展示了YuiJavaScriptC
本文整理了Java中com.googlecode.htmlcompressor.compressor.YuiCssCompressor类的一些代码示例,展示了YuiCssCompressor类的具体用
我目前在 googlecode svn 上托管我的项目,但是我想在另一个 svn 服务器(也在线)上托管它的副本,有人可以建议保持备份和更新的最佳方法吗? 最佳答案 转储和同步会起作用,但它可能最容易
我想在hadoop上运行一个应用程序,在该应用程序中,我具有以下导入:“import com.googlecode.javacpp.BytePointer”。在hadoop上运行它后,我得到了: 13
我有一个使用下面这个链接的网页,现在每次我访问该页面时都会出现一个对话框,要求使用用户名和密码进行身份验证。我以前从未发生过这种情况。这是一个错误还是新的东西,有人以前见过这个,有办法解决这个问题吗?
本文整理了Java中com.googlecode.d2j.reader.zip.ZipUtil类的一些代码示例,展示了ZipUtil类的具体用法。这些代码示例主要来源于Github/Stackover
本文整理了Java中com.googlecode.d2j.util.zip.ZipFile类的一些代码示例,展示了ZipFile类的具体用法。这些代码示例主要来源于Github/Stackoverfl
本文整理了Java中com.googlecode.d2j.util.zip.ZipEntry类的一些代码示例,展示了ZipEntry类的具体用法。这些代码示例主要来源于Github/Stackover
本文整理了Java中com.googlecode.streamflyer.internal.thirdparty.ZzzValidate类的一些代码示例,展示了ZzzValidate类的具体用法。这些
本文整理了Java中com.googlecode.zohhak.api.runners.ZohhakRunner类的一些代码示例,展示了ZohhakRunner类的具体用法。这些代码示例主要来源于Gi
如何在 googlecode 中创建私有(private) svn 存储库。 最佳答案 这是不可能的。来自 FAQ : All open source developers. If you plan
本文整理了Java中com.googlecode.htmlcompressor.compressor.XmlCompressor.removeComments()方法的一些代码示例,展示了XmlCom
本文整理了Java中com.googlecode.htmlcompressor.compressor.XmlCompressor.setRemoveIntertagSpaces()方法的一些代码示例,
本文整理了Java中com.googlecode.htmlcompressor.compressor.XmlCompressor.removeIntertagSpaces()方法的一些代码示例,展示了
本文整理了Java中com.googlecode.htmlcompressor.compressor.XmlCompressor.compress()方法的一些代码示例,展示了XmlCompresso
本文整理了Java中com.googlecode.htmlcompressor.compressor.XmlCompressor.setRemoveComments()方法的一些代码示例,展示了Xml
本文整理了Java中com.googlecode.htmlcompressor.compressor.XmlCompressor.setEnabled()方法的一些代码示例,展示了XmlCompres
本文整理了Java中com.googlecode.htmlcompressor.compressor.XmlCompressor.()方法的一些代码示例,展示了XmlCompressor.()的具体用
我是一名优秀的程序员,十分优秀!