我正在使用mp4parser附加两个音频文件。追加已经完成,但速度很慢,不知道是什么问题。
在这一行上调试器卡住大音频文件,例如大约30分钟的音频文件。
这是代码。
Movie[] inMovies = null;
inMovies = new Movie[]{
MovieCreator.build(fileOne),
MovieCreator.build(fileTwo)};
List<Track> audioTracks = new LinkedList<Track>();
for (Movie m : inMovies) {
for (Track t : m.getTracks()) {
if (t.getHandler().equals("soun")) {
audioTracks.add(t);
}
}
}
Movie result = new Movie();
if (audioTracks.size() > 0) {
result.addTrack(new AppendTrack(audioTracks.toArray(new Track[audioTracks.size()])));
}
Container out = new DefaultMp4Builder().build(result);
String fileName = getFilename();
FileChannel fc = new RandomAccessFile(String.format(fileName), "rw").getChannel();
out.writeContainer(fc);
fc.close();
Manifestfile
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ehrlite"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:allowBackup="true"
android:icon="@drawable/ehr_icon"
android:label="@string/app_name"
android:name="com.webservice.myApplication"
android:theme="@style/AppTheme" >
<activity
android:name="com.ehrlite.LoginActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateVisible|adjustResize"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.ehrlite.MasterActivity"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.ehrlite.MainActivity"
android:screenOrientation="portrait"
>
</activity>
<activity
android:name="com.ehrlite.PrevMemo"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.webviewcall.WebViewActivity"
android:screenOrientation="portrait">
</activity>`enter code here`
<activity
android:name="com.ehrlite.TranscribedActivity"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
android:windowSoftInputMode="adjustPan">
</activity>
</application>
</manifest>
任何人都可以帮助我改善表现, 提前谢谢。
答案 0 :(得分:1)
我找到了答案的解决方案。
我以前遇到过问题。
您正在使用RandomAccessfile
。您需要使用FileOutputStream
Container out = new DefaultMp4Builder().build(result);
String outputFilePath = getfilename();
FileOutputStream fos = new FileOutputStream(new File(outputFilePath));
out.writeContainer(fos.getChannel());
fos.close();
参考:
why are java RandomAccessFile so much slower than FileOutputStream?