Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void adjustAspectRatio(int videoWidth, int videoHeight) {
- int viewWidth = textureView.getWidth();
- int viewHeight = textureView.getHeight();
- double aspectRatio = (double) videoHeight / videoWidth;
- int newWidth, newHeight;
- if (viewHeight > (int) (viewWidth * aspectRatio)) {
- // limited by narrow width; restrict height
- newWidth = viewWidth;
- newHeight = (int) (viewWidth * aspectRatio);
- } else {
- // limited by short height; restrict width
- newWidth = (int) (viewHeight / aspectRatio);
- newHeight = viewHeight;
- }
- int xoff = (viewWidth - newWidth) / 2;
- int yoff = (viewHeight - newHeight) / 2;
- /*Log.v(TAG, "video=" + videoWidth + "x" + videoHeight +
- " view=" + viewWidth + "x" + viewHeight +
- " newView=" + newWidth + "x" + newHeight +
- " off=" + xoff + "," + yoff);*/
- Matrix txform = new Matrix();
- textureView.getTransform(txform);
- txform.setScale((float) newWidth / viewWidth, (float) newHeight / viewHeight);
- //txform.postRotate(10); // just for fun
- txform.postTranslate(xoff, yoff);
- textureView.setTransform(txform);
- }
- private void checkMultiAudioTrack(MediaPlayer mediaPlayer) {
- mediaPlayer.pause();
- MediaPlayer.TrackInfo[] trackInfo = mediaPlayer.getTrackInfo();
- ArrayList<Integer> audioTracksIndex = new ArrayList<>();
- for (int i = 0; i < trackInfo.length; i++) {
- if (trackInfo[i].getTrackType() == MediaPlayer.TrackInfo.MEDIA_TRACK_TYPE_TIMEDTEXT) {
- audioTracksIndex.add(i);
- }
- }
- AlertDialog.Builder builder = new AlertDialog.Builder(VideoPlayer.this);
- builder.setTitle("Select Subtitle Track");
- String[] values = new String[audioTracksIndex.size()];
- for (int i = 0; i < audioTracksIndex.size(); i++) {
- values[i] = i + "." + trackInfo[i].getLanguage().replace("und", "Unknown");
- }
- /*
- * SingleChoice means RadioGroup
- * */
- builder.setSingleChoiceItems(values, 0, (dialog, which) -> mediaPlayer.selectTrack(which))
- .setPositiveButton("Ok", (dialog, which) -> {
- mediaPlayer.selectTrack(which);
- mediaPlayer.start();
- dialog.dismiss();
- }).setNegativeButton("Cancel", (dialog, which) -> dialog.dismiss());
- builder.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment