當前位置: 首頁>>代碼示例>>Java>>正文


Java ExoPlayer類代碼示例

本文整理匯總了Java中com.google.android.exoplayer.ExoPlayer的典型用法代碼示例。如果您正苦於以下問題:Java ExoPlayer類的具體用法?Java ExoPlayer怎麽用?Java ExoPlayer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ExoPlayer類屬於com.google.android.exoplayer包,在下文中一共展示了ExoPlayer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onStateChanged

import com.google.android.exoplayer.ExoPlayer; //導入依賴的package包/類
@Override
public void onStateChanged(boolean playWhenReady, int playbackState) {
    if (playWhenReady && playbackState == ExoPlayer.STATE_READY) {
        notifyTracksChanged(getAllTracks());
        String audioId = getTrackId(TvTrackInfo.TYPE_AUDIO,
                mPlayer.getSelectedTrack(TvTrackInfo.TYPE_AUDIO));
        String videoId = getTrackId(TvTrackInfo.TYPE_VIDEO,
                mPlayer.getSelectedTrack(TvTrackInfo.TYPE_VIDEO));
        String textId = getTrackId(TvTrackInfo.TYPE_SUBTITLE,
                mPlayer.getSelectedTrack(TvTrackInfo.TYPE_SUBTITLE));

        notifyTrackSelected(TvTrackInfo.TYPE_AUDIO, audioId);
        notifyTrackSelected(TvTrackInfo.TYPE_VIDEO, videoId);
        notifyTrackSelected(TvTrackInfo.TYPE_SUBTITLE, textId);
        notifyVideoAvailable();
    }
}
 
開發者ID:nejtv,項目名稱:androidtv-sample,代碼行數:18,代碼來源:RichTvInputService.java

示例2: getStateString

import com.google.android.exoplayer.ExoPlayer; //導入依賴的package包/類
private String getStateString(int state) {
  switch (state) {
    case ExoPlayer.STATE_BUFFERING:
      return "B";
    case ExoPlayer.STATE_ENDED:
      return "E";
    case ExoPlayer.STATE_IDLE:
      return "I";
    case ExoPlayer.STATE_PREPARING:
      return "P";
    case ExoPlayer.STATE_READY:
      return "R";
    default:
      return "?";
  }
}
 
開發者ID:Dreamxiaoxuan,項目名稱:AndroidTvDemo,代碼行數:17,代碼來源:EventLogger.java

示例3: isPlaying

import com.google.android.exoplayer.ExoPlayer; //導入依賴的package包/類
@Override
public boolean isPlaying() {
    if (mInternalPlayer == null)
        return false;
    int state = mInternalPlayer.getPlaybackState();
    switch (state) {
        case ExoPlayer.STATE_BUFFERING:
        case ExoPlayer.STATE_READY:
            return mInternalPlayer.getPlayWhenReady();
        case ExoPlayer.STATE_IDLE:
        case ExoPlayer.STATE_PREPARING:
        case ExoPlayer.STATE_ENDED:
            default:
            return false;
    }
}
 
開發者ID:Dreamxiaoxuan,項目名稱:AndroidTvDemo,代碼行數:17,代碼來源:IjkExoMediaPlayer.java

示例4: isPlaying

import com.google.android.exoplayer.ExoPlayer; //導入依賴的package包/類
@Override
public boolean isPlaying() {
    if (mInternalPlayer == null)
        return false;
    int state = mInternalPlayer.getPlaybackState();
    switch (state) {
        case ExoPlayer.STATE_BUFFERING:
        case ExoPlayer.STATE_READY:
            return mInternalPlayer.getPlayWhenReady();
        case ExoPlayer.STATE_IDLE:
        case ExoPlayer.STATE_PREPARING:
        case ExoPlayer.STATE_ENDED:
        default:
            return false;
    }
}
 
開發者ID:bigjelly,項目名稱:ShaddockVideoPlayer,代碼行數:17,代碼來源:IjkExoMediaPlayer.java

示例5: run

import com.google.android.exoplayer.ExoPlayer; //導入依賴的package包/類
@Override public void run() {
  switch (player.getPlaybackState()) {
    case ExoPlayer.STATE_BUFFERING:
      mlistener.onBuffering(playerControl.getBufferPercentage() + "");
      break;
    case ExoPlayer.STATE_ENDED:
      mlistener.onCompletion();
      break;
    case ExoPlayer.STATE_IDLE:
      break;
    case ExoPlayer.STATE_PREPARING:
      mlistener.onBufferingStarted();
      break;
    case ExoPlayer.STATE_READY:
      mlistener.onBufferingFinished();

      break;
    default:
      break;
  }
  mlistener.onProgressChanged((int) player.getCurrentPosition());
  mainHandler.postDelayed(updatePlayer, 200);
}
 
開發者ID:karanvs,項目名稱:ExVidPlayer,代碼行數:24,代碼來源:ExVidPlayerImp.java

示例6: getCurrentPosition

import com.google.android.exoplayer.ExoPlayer; //導入依賴的package包/類
@MainThread
public long getCurrentPosition() {
    // TODO: More precise time may be necessary.
    MpegTsPlayer mpegTsPlayer = mPlayer;
    long currentTime = mpegTsPlayer != null
            ? mRecordStartTimeMs + mpegTsPlayer.getCurrentPosition() : mRecordStartTimeMs;
    if (mChannel == null && mPlayerState == ExoPlayer.STATE_ENDED) {
        currentTime = mRecordingDuration + mRecordStartTimeMs;
    }
    if (DEBUG) {
        long systemCurrentTime = System.currentTimeMillis();
        Log.d(TAG, "currentTime = " + currentTime
                + " ; System.currentTimeMillis() = " + systemCurrentTime
                + " ; diff = " + (currentTime - systemCurrentTime));
    }
    return currentTime;
}
 
開發者ID:trevd,項目名稱:android_packages_apps_tv,代碼行數:18,代碼來源:TunerSessionWorker.java

示例7: stopPlayback

import com.google.android.exoplayer.ExoPlayer; //導入依賴的package包/類
private void stopPlayback() {
    mChannelDataManager.removeAllCallbacksAndMessages();
    if (mPlayer != null) {
        mPlayer.setPlayWhenReady(false);
        mPlayer.release();
        mPlayer = null;
        mPlayerState = ExoPlayer.STATE_IDLE;
        mPlaybackParams.setSpeed(1.0f);
        mPlayerStarted = false;
        mReportedDrawnToSurface = false;
        mPreparingStartTimeMs = INVALID_TIME;
        mBufferingStartTimeMs = INVALID_TIME;
        mReadyStartTimeMs = INVALID_TIME;
        mSession.sendUiMessage(TunerSession.MSG_UI_HIDE_AUDIO_UNPLAYABLE);
        mSession.notifyTimeShiftStatusChanged(TvInputManager.TIME_SHIFT_STATUS_UNAVAILABLE);
    }
}
 
開發者ID:trevd,項目名稱:android_packages_apps_tv,代碼行數:18,代碼來源:TunerSessionWorker.java

示例8: CustomExoPlayer

import com.google.android.exoplayer.ExoPlayer; //導入依賴的package包/類
public CustomExoPlayer(Context context) {
        this.context = context;
        this.mainHandler = new Handler(Looper.getMainLooper());
        this.userAgent = Util.getUserAgent(context, "ExoPlayerDemo");

        // 1. Instantiate the player.
        player = ExoPlayer.Factory.newInstance(2);
//        // 2. Construct renderers.
//        MediaCodecVideoTrackRenderer videoRenderer = ...
//        MediaCodecAudioTrackRenderer audioRenderer = ...
//        // 3. Inject the renderers through prepare.
//        player.prepare(videoRenderer, audioRenderer);
//        // 4. Pass the surface to the video renderer.
//        player.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
//        // 5. Start playback.
//        player.setPlayWhenReady(true);
    }
 
開發者ID:quanhua92,項目名稱:GLMediaPlayer,代碼行數:18,代碼來源:CustomExoPlayer.java

示例9: onPlayerStateChanged

import com.google.android.exoplayer.ExoPlayer; //導入依賴的package包/類
@Override
public void onPlayerStateChanged(boolean playWhenReady, int state) {
  switch (player.getPlaybackState()) {
    case ExoPlayer.STATE_BUFFERING:
      playerState = "buffering";
      break;
    case ExoPlayer.STATE_ENDED:
      playerState = "ended";
      break;
    case ExoPlayer.STATE_IDLE:
      playerState = "idle";
      break;
    case ExoPlayer.STATE_PREPARING:
      playerState = "preparing";
      break;
    case ExoPlayer.STATE_READY:
      playerState = "ready";
      break;
  }
  updateDebugInfoTextView();
}
 
開發者ID:asifkhan11,項目名稱:ExoPlayer-Demo,代碼行數:22,代碼來源:PlayerActivity.java

示例10: getStateString

import com.google.android.exoplayer.ExoPlayer; //導入依賴的package包/類
private static String getStateString(int state) {
  switch (state) {
    case ExoPlayer.STATE_BUFFERING:
      return "B";
    case ExoPlayer.STATE_ENDED:
      return "E";
    case ExoPlayer.STATE_IDLE:
      return "I";
    case ExoPlayer.STATE_PREPARING:
      return "P";
    case ExoPlayer.STATE_READY:
      return "R";
    default:
      return "?";
  }
}
 
開發者ID:asifkhan11,項目名稱:ExoPlayer-Demo,代碼行數:17,代碼來源:LogcatLogger.java

示例11: run

import com.google.android.exoplayer.ExoPlayer; //導入依賴的package包/類
@Override
public void run() {
  Looper.prepare();
  player = ExoPlayer.Factory.newInstance(1);
  player.addListener(this);
  ExtractorSampleSource  sampleSource = new ExtractorSampleSource(
      uri, new DefaultUriDataSource(context, Util.getUserAgent(context, "ExoPlayerExtVP9Test")),
      new DefaultAllocator(BUFFER_SEGMENT_SIZE), BUFFER_SEGMENT_SIZE * BUFFER_SEGMENT_COUNT,
      new WebmExtractor());
  LibvpxVideoTrackRenderer videoRenderer = new LibvpxVideoTrackRenderer(sampleSource, true);
  player.sendMessage(videoRenderer, LibvpxVideoTrackRenderer.MSG_SET_OUTPUT_BUFFER_RENDERER,
      new VpxVideoSurfaceView(context));
  player.prepare(videoRenderer);
  player.setPlayWhenReady(true);
  Looper.loop();
}
 
開發者ID:asifkhan11,項目名稱:ExoPlayer-Demo,代碼行數:17,代碼來源:VpxPlaybackTest.java

示例12: releasePlayer

import com.google.android.exoplayer.ExoPlayer; //導入依賴的package包/類
private void releasePlayer() {
    if (player != null) {
        Log.d(TAG, "Release player");
        videoPlayerView.stopDebugView();
        playerPosition = player.getCurrentPosition();
        long duration = player.getDuration();
        player.getPlayerControl().pause();
        updatePlaybackState(ExoPlayer.STATE_IDLE);
        updateMediaSessionIntent();
        player.release();
        player = null;
        eventLogger.endSession();
        eventLogger = null;
        timeLogger.endSession();
        timeLogger = null;
        if (playerPosition >= duration) {
            mediaSession.setActive(false);
            mediaSession.release();
            mediaSession = null;
        }
    }
}
 
開發者ID:nextux,項目名稱:sbs-android-tv,代碼行數:23,代碼來源:VideoPlayerActivity.java

示例13: updatePlaybackState

import com.google.android.exoplayer.ExoPlayer; //導入依賴的package包/類
private void updatePlaybackState(int playbackState) {
    PlaybackState.Builder state = new PlaybackState.Builder();
    long position = player.getCurrentPosition();
    if (ExoPlayer.STATE_PREPARING == playbackState) {
        state.setState(PlaybackState.STATE_CONNECTING, position, 1.0f);
    } else if (ExoPlayer.STATE_BUFFERING == playbackState) {
        state.setState(PlaybackState.STATE_BUFFERING, position, 1.0f);
    } else {
        if (player.getPlayerControl().isPlaying()) {
            state.setState(PlaybackState.STATE_PLAYING, position, 1.0f);
        } else {
            state.setState(PlaybackState.STATE_PAUSED, position, 1.0f);
        }
    }
    mediaSession.setPlaybackState(state.build());
}
 
開發者ID:nextux,項目名稱:sbs-android-tv,代碼行數:17,代碼來源:VideoPlayerActivity.java

示例14: getStateString

import com.google.android.exoplayer.ExoPlayer; //導入依賴的package包/類
private String getStateString(int state) {
    switch (state) {
        case ExoPlayer.STATE_BUFFERING:
            return "B";
        case ExoPlayer.STATE_ENDED:
            return "E";
        case ExoPlayer.STATE_IDLE:
            return "I";
        case ExoPlayer.STATE_PREPARING:
            return "P";
        case ExoPlayer.STATE_READY:
            return "R";
        default:
            return "?";
    }
}
 
開發者ID:nextux,項目名稱:sbs-android-tv,代碼行數:17,代碼來源:EventLogger.java

示例15: executeListeners

import com.google.android.exoplayer.ExoPlayer; //導入依賴的package包/類
private void executeListeners() {
    long duration = player.getDuration() / 1000;
    long position = player.getCurrentPosition() / 1000;
    List<Pair<Long, OnTimeReached>> executed = new ArrayList<>();
    if (duration > 0 && (state == ExoPlayer.STATE_READY || state == ExoPlayer.STATE_ENDED)) {
        long remain = duration - position;
        for (Pair<Long, OnTimeReached> listener : listeners) {
            long condition = listener.first;
            if (remain <= condition) {
                Log.d(TAG, "Executing listener, duration=" + duration + ", position=" + position + ", remaining=" + remain);
                listener.second.onPositionRemainingReached(duration, position);
                executed.add(listener);
            }
        }
    }
    listeners.removeAll(executed);
}
 
開發者ID:nextux,項目名稱:sbs-android-tv,代碼行數:18,代碼來源:DurationLogger.java


注:本文中的com.google.android.exoplayer.ExoPlayer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。