I'm working on an android project which needs me to split a video file into some parts(like each of 5 mb) and then individually playing these parts. I have successfully split the video into the parts but these parts are not playing.(maybe missing some playing attributes identified by the player). If someone could provide the solution as to how to play these individual parts without merging(necessary for my project) in context of code only. ps. cannot use any third party software as making an android app.
Here's the code I'm using:
@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();
}
}
Aucun commentaire:
Enregistrer un commentaire