Guest User

Untitled

a guest
Jun 28th, 2021
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.56 KB | None | 0 0
  1. private void adjustAspectRatio(int videoWidth, int videoHeight) {
  2.         int viewWidth = textureView.getWidth();
  3.         int viewHeight = textureView.getHeight();
  4.         double aspectRatio = (double) videoHeight / videoWidth;
  5.  
  6.         int newWidth, newHeight;
  7.         if (viewHeight > (int) (viewWidth * aspectRatio)) {
  8.             // limited by narrow width; restrict height
  9.             newWidth = viewWidth;
  10.             newHeight = (int) (viewWidth * aspectRatio);
  11.         } else {
  12.             // limited by short height; restrict width
  13.             newWidth = (int) (viewHeight / aspectRatio);
  14.             newHeight = viewHeight;
  15.         }
  16.         int xoff = (viewWidth - newWidth) / 2;
  17.         int yoff = (viewHeight - newHeight) / 2;
  18.         /*Log.v(TAG, "video=" + videoWidth + "x" + videoHeight +
  19.                 " view=" + viewWidth + "x" + viewHeight +
  20.                 " newView=" + newWidth + "x" + newHeight +
  21.                 " off=" + xoff + "," + yoff);*/
  22.  
  23.         Matrix txform = new Matrix();
  24.         textureView.getTransform(txform);
  25.         txform.setScale((float) newWidth / viewWidth, (float) newHeight / viewHeight);
  26.         //txform.postRotate(10);          // just for fun
  27.         txform.postTranslate(xoff, yoff);
  28.         textureView.setTransform(txform);
  29.     }
  30.  
  31.  
  32.  
  33. private void checkMultiAudioTrack(MediaPlayer mediaPlayer) {
  34.         mediaPlayer.pause();
  35.         MediaPlayer.TrackInfo[] trackInfo = mediaPlayer.getTrackInfo();
  36.  
  37.         ArrayList<Integer> audioTracksIndex = new ArrayList<>();
  38.  
  39.         for (int i = 0; i < trackInfo.length; i++) {
  40.             if (trackInfo[i].getTrackType() == MediaPlayer.TrackInfo.MEDIA_TRACK_TYPE_TIMEDTEXT) {
  41.                 audioTracksIndex.add(i);
  42.             }
  43.         }
  44.  
  45.         AlertDialog.Builder builder = new AlertDialog.Builder(VideoPlayer.this);
  46.         builder.setTitle("Select Subtitle Track");
  47.         String[] values = new String[audioTracksIndex.size()];
  48.         for (int i = 0; i < audioTracksIndex.size(); i++) {
  49.             values[i] = i + "." + trackInfo[i].getLanguage().replace("und", "Unknown");
  50.         }
  51.         /*
  52.          * SingleChoice means RadioGroup
  53.          * */
  54.         builder.setSingleChoiceItems(values, 0, (dialog, which) -> mediaPlayer.selectTrack(which))
  55.                 .setPositiveButton("Ok", (dialog, which) -> {
  56.                     mediaPlayer.selectTrack(which);
  57.                     mediaPlayer.start();
  58.                     dialog.dismiss();
  59.                 }).setNegativeButton("Cancel", (dialog, which) -> dialog.dismiss());
  60.         builder.show();
  61.     }
Advertisement
Add Comment
Please, Sign In to add comment