Java 类com.google.android.exoplayer.demo.R 实例源码

项目:ExoPlayer-Demo    文件:MainActivity.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    editText_url = (EditText) findViewById(R.id.editText_url);
    button = (Button) findViewById(R.id.play);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, PlayerActivity.class)
                    .setData(Uri.parse(editText_url.getText().toString()))
                    .putExtra(PlayerActivity.CONTENT_ID_EXTRA, "Live Streaming")
                    .putExtra(PlayerActivity.CONTENT_TYPE_EXTRA, Util.TYPE_HLS);
            startActivity(intent);
        }
    });
}
项目:ExoPlayer-Demo    文件:PlayerActivity.java   
public void showAudioPopup(View v) {
    PopupMenu popup = new PopupMenu(this, v);
    Menu menu = popup.getMenu();
    menu.add(Menu.NONE, Menu.NONE, Menu.NONE, R.string.enable_background_audio);
    final MenuItem backgroundAudioItem = menu.findItem(0);
    backgroundAudioItem.setCheckable(true);
    backgroundAudioItem.setChecked(enableBackgroundAudio);
    OnMenuItemClickListener clickListener = new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (item == backgroundAudioItem) {
                enableBackgroundAudio = !item.isChecked();
                return true;
            }
            return false;
        }
    };
    configurePopupWithTracks(popup, clickListener, DemoPlayer.TYPE_AUDIO);
    popup.show();
}
项目:ExoPlayer-Demo    文件:PlayerActivity.java   
public void showVerboseLogPopup(View v) {
    PopupMenu popup = new PopupMenu(this, v);
    Menu menu = popup.getMenu();
    menu.add(Menu.NONE, 0, Menu.NONE, R.string.logging_normal);
    menu.add(Menu.NONE, 1, Menu.NONE, R.string.logging_verbose);
    menu.setGroupCheckable(Menu.NONE, true, true);
    menu.findItem((VerboseLogUtil.areAllTagsEnabled()) ? 1 : 0).setChecked(true);
    popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (item.getItemId() == 0) {
                VerboseLogUtil.setEnableAllTags(false);
            } else {
                VerboseLogUtil.setEnableAllTags(true);
            }
            return true;
        }
    });
    popup.show();
}
项目:android-exoplayer    文件:FullPlayerActivity.java   
public void showAudioPopup(View v) {
  PopupMenu popup = new PopupMenu(this, v);
  Menu menu = popup.getMenu();
  menu.add(Menu.NONE, Menu.NONE, Menu.NONE, R.string.enable_background_audio);
  final MenuItem backgroundAudioItem = menu.findItem(0);
  backgroundAudioItem.setCheckable(true);
  backgroundAudioItem.setChecked(enableBackgroundAudio);
  OnMenuItemClickListener clickListener = new OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
      if (item == backgroundAudioItem) {
        enableBackgroundAudio = !item.isChecked();
        return true;
      }
      return false;
    }
  };
  configurePopupWithTracks(popup, clickListener, DemoPlayer.TYPE_AUDIO);
  popup.show();
}
项目:android-exoplayer    文件:FullPlayerActivity.java   
public void showVerboseLogPopup(View v) {
  PopupMenu popup = new PopupMenu(this, v);
  Menu menu = popup.getMenu();
  menu.add(Menu.NONE, 0, Menu.NONE, R.string.logging_normal);
  menu.add(Menu.NONE, 1, Menu.NONE, R.string.logging_verbose);
  menu.setGroupCheckable(Menu.NONE, true, true);
  menu.findItem((VerboseLogUtil.areAllTagsEnabled()) ? 1 : 0).setChecked(true);
  popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
      if (item.getItemId() == 0) {
        VerboseLogUtil.setEnableAllTags(false);
      } else {
        VerboseLogUtil.setEnableAllTags(true);
      }
      return true;
    }
  });
  popup.show();
}
项目:ExoPlayerController    文件:GoatMediaController.java   
private void init(Context context) {
    this.mContext = context;
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
       View viewRoot = inflater.inflate(R.layout.uvv_player_controller, this);
       viewRoot.setOnTouchListener(mTouchListener);
       initControllerView(viewRoot);
}
项目:ExoPlayerController    文件:GoatMediaController.java   
private void updatePausePlay() {
    if (mPlayer.isPlaying()) {
        mTurnButton.setImageResource(R.drawable.uvv_stop_btn);
    } else {
        mTurnButton.setImageResource(R.drawable.uvv_player_player_btn);
    }
}
项目:ExoPlayerController    文件:GoatMediaController.java   
public void updateScaleButton() {
    if (isFullScreen()) {
        mScaleButton.setImageResource(R.drawable.uvv_star_zoom_in);
    } else {
        mScaleButton.setImageResource(R.drawable.uvv_player_scale_btn);
    }
}
项目:ExoPlayerController    文件:GoatMediaController.java   
private void showCenterView(int resId) {
    switch (resId) {
case R.id.loading_layout:
    if (loadingLayout.getVisibility() != VISIBLE) {
            loadingLayout.setVisibility(VISIBLE);
        }
        if (mCenterPlayButton.getVisibility() == VISIBLE) {
            mCenterPlayButton.setVisibility(GONE);
        }
        if (errorLayout.getVisibility() == VISIBLE) {
            errorLayout.setVisibility(GONE);
        }
    break;
case R.id.center_play_btn:
    if (mCenterPlayButton.getVisibility() != VISIBLE) {
        mCenterPlayButton.setVisibility(VISIBLE);
    }
    if (loadingLayout.getVisibility() == VISIBLE) {
        loadingLayout.setVisibility(GONE);
    }
    if (errorLayout.getVisibility() == VISIBLE) {
        errorLayout.setVisibility(GONE);
    }
    break;
case R.id.error_layout:
    if (errorLayout.getVisibility() != VISIBLE) {
        errorLayout.setVisibility(VISIBLE);
    }
    if (mCenterPlayButton.getVisibility() == VISIBLE) {
        mCenterPlayButton.setVisibility(GONE);
    }
    if (loadingLayout.getVisibility() == VISIBLE) {
        loadingLayout.setVisibility(GONE);
    }
    break;
default:
    break;
}
  }
项目:ExoPlayerController    文件:GoatMediaController.java   
@Override
public void handleMessage(Message msg) {
    int pos;
    switch (msg.what) {
        case FADE_OUT:
            hide();
            break;
        case SHOW_PROGRESS:
            pos = setProgress();
            if (!mDragging && mShowing && mPlayer.isPlaying()) {
                msg = obtainMessage(SHOW_PROGRESS);
                sendMessageDelayed(msg, 1000 - (pos % 1000));
            }
            break;
        case SHOW_LOADING:
            show();
            showCenterView(R.id.loading_layout);
            break;
        case SHOW_COMPLETE:
            showCenterView(R.id.center_play_btn);
            break;
        case SHOW_ERROR:
            show();
            showCenterView(R.id.error_layout);
            break;
        case HIDE_LOADING:
        case HIDE_ERROR:
        case HIDE_COMPLETE:
            hide();
            hideCenterView();
            break;
    }
}
项目:ExoPlayer-Demo    文件:PlayerActivity.java   
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions,
                                       int[] grantResults) {
    if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        preparePlayer(true);
    } else {
        Toast.makeText(getApplicationContext(), R.string.storage_permission_denied,
                Toast.LENGTH_LONG).show();
        finish();
    }
}
项目:ExoPlayer-Demo    文件:PlayerActivity.java   
@Override
public void onError(Exception e) {
    String errorString = null;
    if (e instanceof UnsupportedDrmException) {
        // Special case DRM failures.
        UnsupportedDrmException unsupportedDrmException = (UnsupportedDrmException) e;
        errorString = getString(Util.SDK_INT < 18 ? R.string.error_drm_not_supported
                : unsupportedDrmException.reason == UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME
                ? R.string.error_drm_unsupported_scheme : R.string.error_drm_unknown);
    } else if (e instanceof ExoPlaybackException
            && e.getCause() instanceof DecoderInitializationException) {
        // Special case for decoder initialization failures.
        DecoderInitializationException decoderInitializationException =
                (DecoderInitializationException) e.getCause();
        if (decoderInitializationException.decoderName == null) {
            if (decoderInitializationException.getCause() instanceof DecoderQueryException) {
                errorString = getString(R.string.error_querying_decoders);
            } else if (decoderInitializationException.secureDecoderRequired) {
                errorString = getString(R.string.error_no_secure_decoder,
                        decoderInitializationException.mimeType);
            } else {
                errorString = getString(R.string.error_no_decoder,
                        decoderInitializationException.mimeType);
            }
        } else {
            errorString = getString(R.string.error_instantiating_decoder,
                    decoderInitializationException.decoderName);
        }
    }
    if (errorString != null) {
        Toast.makeText(getApplicationContext(), errorString, Toast.LENGTH_LONG).show();
    }
    playerNeedsPrepare = true;
    updateButtonVisibilities();
    showControls();
}
项目:ExoPlayer-Demo    文件:PlayerActivity.java   
private void configurePopupWithTracks(PopupMenu popup,
                                      final OnMenuItemClickListener customActionClickListener,
                                      final int trackType) {
    if (player == null) {
        return;
    }
    int trackCount = player.getTrackCount(trackType);
    if (trackCount == 0) {
        return;
    }
    popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return (customActionClickListener != null
                    && customActionClickListener.onMenuItemClick(item))
                    || onTrackItemClick(item, trackType);
        }
    });
    Menu menu = popup.getMenu();
    // ID_OFFSET ensures we avoid clashing with Menu.NONE (which equals 0).
    menu.add(MENU_GROUP_TRACKS, DemoPlayer.TRACK_DISABLED + ID_OFFSET, Menu.NONE, R.string.off);
    for (int i = 0; i < trackCount; i++) {
        menu.add(MENU_GROUP_TRACKS, i + ID_OFFSET, Menu.NONE,
                buildTrackName(player.getTrackFormat(trackType, i)));
    }
    menu.setGroupCheckable(MENU_GROUP_TRACKS, true, true);
    menu.findItem(player.getSelectedTrack(trackType) + ID_OFFSET).setChecked(true);
}
项目:android-exoplayer    文件:FullPlayerActivity.java   
private void configurePopupWithTracks(PopupMenu popup,
    final OnMenuItemClickListener customActionClickListener,
    final int trackType) {
  if (player == null) {
    return;
  }
  String[] tracks = player.getTracks(trackType);
  if (tracks == null) {
    return;
  }
  popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
      return (customActionClickListener != null
          && customActionClickListener.onMenuItemClick(item))
          || onTrackItemClick(item, trackType);
    }
  });
  Menu menu = popup.getMenu();
  // ID_OFFSET ensures we avoid clashing with Menu.NONE (which equals 0)
  menu.add(MENU_GROUP_TRACKS, DemoPlayer.DISABLED_TRACK + ID_OFFSET, Menu.NONE, R.string.off);
  if (tracks.length == 1 && TextUtils.isEmpty(tracks[0])) {
    menu.add(MENU_GROUP_TRACKS, DemoPlayer.PRIMARY_TRACK + ID_OFFSET, Menu.NONE, R.string.on);
  } else {
    for (int i = 0; i < tracks.length; i++) {
      menu.add(MENU_GROUP_TRACKS, i + ID_OFFSET, Menu.NONE, tracks[i]);
    }
  }
  menu.setGroupCheckable(MENU_GROUP_TRACKS, true, true);
  menu.findItem(player.getSelectedTrackIndex(trackType) + ID_OFFSET).setChecked(true);
}
项目:android-exoplayer    文件:FullPlayerActivity.java   
private float getCaptionFontSize() {
  Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
      .getDefaultDisplay();
  Point displaySize = new Point();
  display.getSize(displaySize);
  return Math.max(getResources().getDimension(R.dimen.subtitle_minimum_font_size),
      CAPTION_LINE_HEIGHT_RATIO * Math.min(displaySize.x, displaySize.y));
}
项目:android-exoplayer    文件:SimplePlayerActivity.java   
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  Intent intent = getIntent();
  contentUri = intent.getData();
  contentType = intent.getIntExtra(DemoUtil.CONTENT_TYPE_EXTRA, DemoUtil.TYPE_OTHER);
  contentId = intent.getStringExtra(DemoUtil.CONTENT_ID_EXTRA);

  mainHandler = new Handler(getMainLooper());
  builder = getRendererBuilder();

  setContentView(R.layout.player_activity_simple);
  View root = findViewById(R.id.root);
  root.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View arg0, MotionEvent arg1) {
      if (arg1.getAction() == MotionEvent.ACTION_DOWN) {
        toggleControlsVisibility();
      }
      return true;
    }
  });

  mediaController = new MediaController(this);
  mediaController.setAnchorView(root);
  shutterView = findViewById(R.id.shutter);
  surfaceView = (VideoSurfaceView) findViewById(R.id.surface_view);
  surfaceView.getHolder().addCallback(this);

  DemoUtil.setDefaultCookieManager();
}
项目:ExoPlayerController    文件:GoatMediaController.java   
private void initControllerView(View v) {
    mTitleLayout = v.findViewById(R.id.title_part);
       mControlLayout = v.findViewById(R.id.control_layout);
       loadingLayout = (ViewGroup) v.findViewById(R.id.loading_layout);
       errorLayout = (ViewGroup) v.findViewById(R.id.error_layout);
       mTurnButton = (ImageButton) v.findViewById(R.id.turn_button);
       mScaleButton = (ImageButton) v.findViewById(R.id.scale_button);
       mCenterPlayButton = v.findViewById(R.id.center_play_btn);
       mBackButton = v.findViewById(R.id.back_btn);

       if (mTurnButton != null) {
        mTurnButton.requestFocus();
        mTurnButton.setOnClickListener(mPauseListener);
       }

       if (mScaleButton != null) {
        mScaleButton.requestFocus();
        mScaleButton.setOnClickListener(mScaleListener);
       }

       // Restart play-back
       if (mCenterPlayButton != null) {
        mCenterPlayButton.requestFocus();
        mCenterPlayButton.setOnClickListener(mCenterPlayListener);
       }

       if (mBackButton != null) {
        mBackButton.setOnClickListener(mBackListener);
       }

       mProgress = (ProgressBar) v.findViewById(R.id.seekbar);
       if (mProgress != null) {
           if (mProgress instanceof SeekBar) {
               SeekBar seeker = (SeekBar) mProgress;
               seeker.setOnSeekBarChangeListener(mSeekListener);
           }
           mProgress.setMax(1000);
       }

       mEndTime = (TextView) v.findViewById(R.id.duration);
       mCurrentTime = (TextView) v.findViewById(R.id.has_played);
       mTitle = (TextView) v.findViewById(R.id.title);

       mFormatBuilder = new StringBuilder();
       mFormatter = new Formatter(mFormatBuilder, Locale.getDefault());
}
项目:ExoPlayer-Demo    文件:PlayerActivity.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.player_activity);
    View root = findViewById(R.id.root);
    root.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                toggleControlsVisibility();
            } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                view.performClick();
            }
            return true;
        }
    });
    root.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE
                    || keyCode == KeyEvent.KEYCODE_MENU) {
                return false;
            }
            return mediaController.dispatchKeyEvent(event);
        }
    });

    shutterView = findViewById(R.id.shutter);
    debugRootView = findViewById(R.id.controls_root);

    videoFrame = (AspectRatioFrameLayout) findViewById(R.id.video_frame);
    surfaceView = (SurfaceView) findViewById(R.id.surface_view);
    surfaceView.getHolder().addCallback(this);
    debugTextView = (TextView) findViewById(R.id.debug_text_view);

    playerStateTextView = (TextView) findViewById(R.id.player_state_view);
    subtitleLayout = (SubtitleLayout) findViewById(R.id.subtitles);

    mediaController = new KeyCompatibleMediaController(this);
    mediaController.setAnchorView(root);
    retryButton = (Button) findViewById(R.id.retry_button);
    retryButton.setOnClickListener(this);
    videoButton = (Button) findViewById(R.id.video_controls);
    audioButton = (Button) findViewById(R.id.audio_controls);
    textButton = (Button) findViewById(R.id.text_controls);

    CookieHandler currentHandler = CookieHandler.getDefault();
    if (currentHandler != defaultCookieManager) {
        CookieHandler.setDefault(defaultCookieManager);
    }

    audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this);
    audioCapabilitiesReceiver.register();
}
项目:android-exoplayer    文件:FullPlayerActivity.java   
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  Intent intent = getIntent();
  contentUri = intent.getData();
  contentType = intent.getIntExtra(DemoUtil.CONTENT_TYPE_EXTRA, DemoUtil.TYPE_OTHER);
  contentId = intent.getStringExtra(DemoUtil.CONTENT_ID_EXTRA);

  setContentView(R.layout.player_activity_full);
  View root = findViewById(R.id.root);
  root.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View arg0, MotionEvent arg1) {
      if (arg1.getAction() == MotionEvent.ACTION_DOWN) {
        toggleControlsVisibility();
      }
      return true;
    }
  });

  shutterView = findViewById(R.id.shutter);
  debugRootView = findViewById(R.id.controls_root);

  surfaceView = (VideoSurfaceView) findViewById(R.id.surface_view);
  surfaceView.getHolder().addCallback(this);
  debugTextView = (TextView) findViewById(R.id.debug_text_view);

  playerStateTextView = (TextView) findViewById(R.id.player_state_view);
  subtitleView = (SubtitleView) findViewById(R.id.subtitles);

  mediaController = new MediaController(this);
  mediaController.setAnchorView(root);
  retryButton = (Button) findViewById(R.id.retry_button);
  retryButton.setOnClickListener(this);
  videoButton = (Button) findViewById(R.id.video_controls);
  audioButton = (Button) findViewById(R.id.audio_controls);
  textButton = (Button) findViewById(R.id.text_controls);

  DemoUtil.setDefaultCookieManager();
}
项目:android-exoplayer    文件:SimplePlayerActivity.java   
private void onError(Exception e) {
  Log.e(TAG, "Playback failed", e);
  Toast.makeText(this, R.string.failed, Toast.LENGTH_SHORT).show();
  finish();
}