私はビデオファイルをいくつかの部分に分割して個別に再生する必要があるアンドロイドプロジェクトに取り組んでいます。 ビデオをパートに分割しましたが、これらのパートは再生されていません(プレーヤーによって識別された再生属性が不足している可能性があります)。 誰かが、コードのコンテキストでのみ、マージせずにこれらの個々のパートをどのようにプレイするかについての解決策を提供できれば(私のプロジェクトに必要です)。 ps。 Androidアプリを作成する際にサードパーティのソフトウェアを使用することはできません。あなただけの部分にバイナリファイルを分割している分割されたビデオファイルをアンドロイドで再生する(分割されたJavaを使用)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final TextView textView = (TextView) findViewById(R.id.textView);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
textView.setText("Successfull");
splitFile(new File(Environment.getExternalStorageDirectory() + "/testing1/video.mp4"));
}
}
);
}
public static void splitFile(File f) {
int partCounter = 1;//I like to name parts from 001, 002, 003, ...
//you can change it to 0 if you want 000, 001, ...
int sizeOfFiles = 1024 * 1024 * 10;// 10MB
byte[] buffer = new byte[sizeOfFiles];
try (BufferedInputStream bis = new BufferedInputStream(
new FileInputStream(f))) {//try-with-resources to ensure closing stream
String name = f.getName();
int tmp = 0;
while ((tmp = bis.read(buffer)) > 0) {
//write each chunk of data into separate file with different number in name
File newFile = new File(f.getParent(), name + "."
+ String.format("%03d", partCounter++)+".mp4");
try (FileOutputStream out = new FileOutputStream(newFile)) {
out.write(buffer, 0, tmp);//tmp is chunk size
}
}
} catch (Exception e) {
e.printStackTrace();
}
}