content: package tv.danmaku.ijk.media.sample.widget.media;
  
  import android.content.Context;
  import android.os.Handler;
  import android.os.Message;
  import android.view.View;
  import android.widget.TableLayout;
  
  import java.util.HashMap;
  import java.util.Locale;
  
  import com.example.videoeditordemo.R;
  
  import tv.danmaku.ijk.media.player.IMediaPlayer;
  import tv.danmaku.ijk.media.player.IjkMediaPlayer;
  import tv.danmaku.ijk.media.player.MediaPlayerProxy;
  
  public class InfoHudViewHolder {
      private TableLayoutBinder mTableLayoutBinder;
      private HashMap<Integer, View> mRowMap = new HashMap<Integer, View>();
      private IMediaPlayer mMediaPlayer;
  
      public InfoHudViewHolder(Context context, TableLayout tableLayout) {
          mTableLayoutBinder = new TableLayoutBinder(context, tableLayout);
  
          appendRow(R.string.fps_decode);
          appendRow(R.string.fps_output);
      }
  
      private void appendSection(int nameId) {
          mTableLayoutBinder.appendSection(nameId);
      }
  
      private void appendRow(int nameId) {
          View rowView = mTableLayoutBinder.appendRow2(nameId, null);
          mRowMap.put(nameId, rowView);
      }
  
      private void setRowValue(int id, String value) {
          View rowView = mRowMap.get(id);
          if (rowView == null) {
              rowView = mTableLayoutBinder.appendRow2(id, value);
              mRowMap.put(id, rowView);
          } else {
              mTableLayoutBinder.setValueText(rowView, value);
          }
      }
  
      public void setMediaPlayer(IMediaPlayer mp) {
          mMediaPlayer = mp;
          if (mMediaPlayer != null) {
              mHandler.sendEmptyMessageDelayed(MSG_UPDATE_HUD, 500);
          } else {
              mHandler.removeMessages(MSG_UPDATE_HUD);
          }
      }
  
      private static final int MSG_UPDATE_HUD = 1;
      private Handler mHandler = new Handler() {
          @Override
          public void handleMessage(Message msg) {
              switch (msg.what) {
                  case MSG_UPDATE_HUD: {
                      InfoHudViewHolder holder = InfoHudViewHolder.this;
                      IjkMediaPlayer mp = null;
                      if (mMediaPlayer == null)
                          break;
                      if (mMediaPlayer instanceof IjkMediaPlayer) {
                          mp = (IjkMediaPlayer) mMediaPlayer;
                      } else if (mMediaPlayer instanceof MediaPlayerProxy) {
                          MediaPlayerProxy proxy = (MediaPlayerProxy) mMediaPlayer;
                          IMediaPlayer internal = proxy.getInternalMediaPlayer();
                          if (internal != null && internal instanceof IjkMediaPlayer)
                              mp = (IjkMediaPlayer) internal;
                      }
                      if (mp == null)
                          break;
  
                      float fpsOutput = mp.getVideoOutputFramesPerSecond();
                      float fpsDecode = mp.getVideoDecodeFramesPerSecond();
                      setRowValue(R.string.fps_decode, String.format(Locale.US, "%.2f", fpsDecode));
                      setRowValue(R.string.fps_output, String.format(Locale.US, "%.2f", fpsOutput));
  
                      mHandler.removeMessages(MSG_UPDATE_HUD);
                      mHandler.sendEmptyMessageDelayed(MSG_UPDATE_HUD, 500);
                  }
              }
          }
      };
  }
  