Java 类com.google.android.exoplayer2.trackselection.AdaptiveVideoTrackSelection 实例源码

项目:videoPickPlayer    文件:CustomExoPlayerView.java   
public void loadVideo(){
//        CommonTools.showErrorLog("test"+"11111111111");
//        CommonTools.showErrorLog("test"+playerPosition);
        if (player == null){
            TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(BANDWIDTH_METER);
            trackSelector = new DefaultTrackSelector(mainHandler, videoTrackSelectionFactory);
            player = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, new DefaultLoadControl(), null, false);
            player.addListener(this);
            setPlayer(player);
//            CommonTools.showErrorLog("test"+"222222222");
            if (playerPosition > 0){
//                CommonTools.showErrorLog("test"+"3333333333");
                player.seekTo(playerPosition);
            }
            player.setPlayWhenReady(isAutoPlay);
        }
        if (uri == null){
//            CommonTools.showToast(getContext(), "请选择一个视频来播放");
            return;
        }
        MediaSource mediaSource = buildMediaSource(uri, null);
        player.prepare(mediaSource);
    }
项目:react-native-videoplayer    文件:ReactExoplayerView.java   
private void initializePlayer() {
    if (player == null) {
        TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(BANDWIDTH_METER);
        trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
        player = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, new DefaultLoadControl());
        player.addListener(this);
        exoPlayerView.setPlayer(player);
        if (isTimelineStatic) {
            if (playerPosition == C.TIME_UNSET) {
                player.seekToDefaultPosition(playerWindow);
            } else {
                player.seekTo(playerWindow, playerPosition);
            }
        }
        audioBecomingNoisyReceiver.setListener(this);
        setPlayWhenReady(!isPaused);
        playerNeedsSource = true;
    }
    if (playerNeedsSource && srcUri != null) {
        MediaSource mediaSource = buildMediaSource(srcUri, extension);
        mediaSource = repeat ? new LoopingMediaSource(mediaSource) : mediaSource;
        player.prepare(mediaSource, !shouldRestorePosition, true);
        playerNeedsSource = false;

        eventEmitter.loadStart();
        loadVideoStarted = true;
    }
}
项目:lostfilm-android-client    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if (!isPlaying) {
        Handler mainHandler = new Handler();
        BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
        TrackSelection.Factory videoTrackSelectionFactory =
                new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
        TrackSelector trackSelector =
                new DefaultTrackSelector(videoTrackSelectionFactory);

        LoadControl loadControl = new DefaultLoadControl();

        SimpleExoPlayer player =
                ExoPlayerFactory.newSimpleInstance(MainActivity.this, trackSelector, loadControl);
        SimpleExoPlayerView playerView = (SimpleExoPlayerView) findViewById(R.id.videoView);
        playerView.setPlayer(player);
        DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(MainActivity.this,
                Util.getUserAgent(MainActivity.this, "yourApplicationName"));
        MediaSource mediaSource = new ExtractorMediaSource(Uri.parse("https://r7---sn-3c27ln7k.googlevideo.com/videoplayback?id=6fb497d0971b8cdf&itag=22&source=picasa&begin=0&requiressl=yes&mm=30&mn=sn-3c27ln7k&ms=nxu&mv=m&nh=IgphcjAzLmticDAxKgkxMjcuMC4wLjE&pl=22&sc=yes&mime=video/mp4&lmt=1486083166327499&mt=1486135406&ip=134.249.158.189&ipbits=8&expire=1486164239&sparams=ip,ipbits,expire,id,itag,source,requiressl,mm,mn,ms,mv,nh,pl,sc,mime,lmt&signature=3BB06D8D4294F8C49B3CE910B3D6849954302BB1.02ABE00700DFCEF715E72D0EFB73B67841E659F8&key=ck2&ratebypass=yes&title=%5BAnime365%5D%20Kuzu%20no%20Honkai%20-%2004%20(t1174045)"), dataSourceFactory,
                new DefaultExtractorsFactory(), null, null);
        player.prepare(mediaSource);
        player.setPlayWhenReady(true);

    }
}
项目:QSVideoPlayer    文件:ExoMedia.java   
@Override
public void doPrepar(Context context, String url, Map<String, String> headers) {
    release();
    TrackSelection.Factory videoTrackSelectionFactory =
            new AdaptiveVideoTrackSelection.Factory(BANDWIDTH_METER);
    DefaultTrackSelector trackSelector = new DefaultTrackSelector(mainThreadHandler, videoTrackSelectionFactory);
    simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(context, trackSelector, new DefaultLoadControl(),
            null, false);
    simpleExoPlayer.setPlayWhenReady(true);
    MediaSource mediaSource = buildMediaSource(context, Uri.parse(url));
    simpleExoPlayer.addListener(ExoMedia.this);
    simpleExoPlayer.setVideoListener(ExoMedia.this);
    simpleExoPlayer.prepare(mediaSource, true, true);

}
项目:MyAnimeViewer    文件:VideoDetailsFragment.java   
private TrackSelector createTrackSelector() {
    // Create a default TrackSelector
    // Measures bandwidth during playback. Can be null if not required.
    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    TrackSelection.Factory videoTrackSelectionFactory =
            new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
    TrackSelector trackSelector =
            new DefaultTrackSelector(videoTrackSelectionFactory);
    return trackSelector;
}
项目:MyAnimeViewer    文件:OfflineVideoDetailsFragment.java   
private TrackSelector createTrackSelector() {
    // Create a default TrackSelector
    // Measures bandwidth during playback. Can be null if not required.
    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    TrackSelection.Factory videoTrackSelectionFactory =
            new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
    TrackSelector trackSelector =
            new DefaultTrackSelector(videoTrackSelectionFactory);
    return trackSelector;
}
项目:MyAnimeViewer    文件:VideoPlayerActivity.java   
private TrackSelector createTrackSelector() {
    // Create a default TrackSelector
    // Measures bandwidth during playback. Can be null if not required.
    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    TrackSelection.Factory videoTrackSelectionFactory =
            new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
    TrackSelector trackSelector =
            new DefaultTrackSelector(videoTrackSelectionFactory);
    return trackSelector;
}
项目:itplayer    文件:PlayerActivity.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_player);

    media = (MediaFile) getIntent().getSerializableExtra(MEDIA);

    videoFragment = (VideoFragment) getFragmentManager().findFragmentById(R.id.playback_fragment);
    VideoFragmentGlueHost glueHost = new VideoFragmentGlueHost(videoFragment);

    subtitleView = (SubtitleView) findViewById(R.id.subtitle_view);
    if (subtitleView != null) {
        subtitleView.setUserDefaultStyle();
        subtitleView.setUserDefaultTextSize();
    }

    Handler mainHandler = new Handler();
    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
    MappingTrackSelector trackSelector = new DefaultTrackSelector(mainHandler, videoTrackSelectionFactory);
    LoadControl loadControl = new DefaultLoadControl();
    player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);
    player.addListener(this);
    player.setTextOutput(this);

    glueHelper = new ExoPlayerGlue(player, trackSelector, this);
    glueHelper.setHost(glueHost);

    session = new MediaSession(this, "ITPlayer");
    session.setCallback(new ExoPlayerMediaSessionCalback(player));
    session.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
    session.setActive(true);

    MediaMetadata.Builder metaBuilder = new MediaMetadata.Builder();
    session.setMetadata(metaBuilder.build());

    new SourceTask().execute(media);
}
项目:Loop    文件:VideoDetailsFragment.java   
private TrackSelector createTrackSelector(){
    // Create a default TrackSelector
    // Measures bandwidth during playback. Can be null if not required.
    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    TrackSelection.Factory videoTrackSelectionFactory =
            new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
    TrackSelector trackSelector =
            new DefaultTrackSelector(videoTrackSelectionFactory);
    return trackSelector;
}
项目:TFG-SmartU-La-red-social    文件:VideoActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video);
    Bundle bundle = getIntent().getExtras();
    if(bundle!=null && bundle.containsKey("multimedia")) {

        Multimedia multimedia = bundle.getParcelable("multimedia");
        SimpleExoPlayerView videoView = (SimpleExoPlayerView) findViewById(R.id.video);

        // 1. Crea un slector de pista por defecto
        BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
        TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
        TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

        // 2. Creo un control para el player
        LoadControl loadControl = new DefaultLoadControl();

        // 3. Creo el player con los componentes anteriores
        player = ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector, loadControl);

        //Obtengo la URL completa del archivo de video
        Uri uri = Uri.parse(ConsultasBBDD.server + ConsultasBBDD.imagenes +  multimedia.getUrl());

        //A la vista le establezco el reproductor que va a usar
        videoView.setPlayer(player);

        // Procuce que se instancie el DataSource a través de los datos del video que ha sido cargado.
        DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getApplicationContext(), Util.getUserAgent(getApplicationContext(), "SmartU"));
        // Produce un extractor que parsea el video.
        ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
        // Construyo un MediaSource con el formato y los datos del video para asignarselo al reproductor.
        MediaSource videoSource = new ExtractorMediaSource(uri, dataSourceFactory, extractorsFactory, null, null);
        // If has subtitles load video with subtitles
        if (multimedia.getUrlSubtitulos() != null && multimedia.getUrlSubtitulos().compareTo("") != 0) {
            //Obtengo la URL completa para los subtitulos del video
            Uri subtitulosUri = Uri.parse(ConsultasBBDD.server + ConsultasBBDD.imagenes +  multimedia.getUrlSubtitulos());
            //Asigno el formato de los subtitulos
            Format textFormat = Format.createTextSampleFormat(null, MimeTypes.TEXT_VTT,
                    null, Format.NO_VALUE, Format.NO_VALUE, Locale.getDefault().getLanguage(), null);
            //Creo un MediaSource para los subtitulos para añadirselos al video
            MediaSource subtitleSource = new SingleSampleMediaSource(subtitulosUri, dataSourceFactory, textFormat, C.TIME_UNSET);
            // Mezcla el video con los subtitulos
            MergingMediaSource mergedSource = new MergingMediaSource(videoSource, subtitleSource);
            // Preparo el reproductor con los subtitulos y el video
            player.prepare(mergedSource);
        } else // Si no tiene subtitulos preparo solo el video
            player.prepare(videoSource);
    }
}
项目:Cluttr    文件:VideoActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video);
    ButterKnife.bind(this);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
    getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

    path = getIntent().getExtras().getString("MEDIA_URI");

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            finish();
        }
    });

    TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveVideoTrackSelection.Factory(null);
    TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
    LoadControl loadControl = new DefaultLoadControl();

    player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);

    playerView.setPlayer(player);

    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "org.polaric.cluttr"), null);
    ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
    MediaSource videoSource = new ExtractorMediaSource(Uri.parse(path), dataSourceFactory, extractorsFactory, null, null);

    player.prepare(videoSource);

    playerView.setControllerVisibilityListener(new PlaybackControlView.VisibilityListener() {
        @Override
        public void onVisibilityChange(int visibility) {
            if  (visibility==View.VISIBLE) {
                fab.show();
            } else {
                fab.hide();
            }
        }
    });
}
项目:ExoPlayer-Offline    文件:ExoHostedTest.java   
@SuppressWarnings("unused")
protected MappingTrackSelector buildTrackSelector(HostActivity host,
    BandwidthMeter bandwidthMeter) {
  return new DefaultTrackSelector(new AdaptiveVideoTrackSelection.Factory(bandwidthMeter));
}
项目:BeatPulse    文件:MusicService.java   
@Override
public IBinder onBind(Intent intent) {
    //onBind is only called when the first client connects. All other bind attempts just return the same binder object
    Handler handler = new Handler();
    BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
    TrackSelection.Factory trackSelection = new AdaptiveVideoTrackSelection.Factory(bandwidthMeter);
    TrackSelector trackSelector = new DefaultTrackSelector(handler, trackSelection);
    LoadControl loadControl = new DefaultLoadControl();

    player = ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector, loadControl);
    player.addListener(new ExoPlayer.EventListener() {
        @Override
        public void onLoadingChanged(boolean isLoading) {

        }

        @Override
        public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
            if(playbackState == ExoPlayer.STATE_ENDED){
                if(replayMode == REPLAY_ONE){
                    playNext(true, false);
                } else if (replayMode != STOP_AFTER_NEXT) {
                    playNext(false, false);
                }
            }
        }

        @Override
        public void onTimelineChanged(Timeline timeline, Object manifest) {

        }

        @Override
        public void onPlayerError(ExoPlaybackException error) {

        }

        @Override
        public void onPositionDiscontinuity() {

        }
    });
    return binder;
}
项目:cpe-manifest-android-experience    文件:ECVideoViewFragment.java   
@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
    videoView = (SimpleExoPlayerView) view.findViewById(R.id.ec_video_view);
    mediaDataSourceFactory = buildDataSourceFactory(true);
    if (videoView != null){
        @SimpleExoPlayer.ExtensionRendererMode int extensionRendererMode = SimpleExoPlayer.EXTENSION_RENDERER_MODE_ON;//SimpleExoPlayer.EXTENSION_RENDERER_MODE_OFF;
        TrackSelection.Factory videoTrackSelectionFactory =
                        new AdaptiveVideoTrackSelection.Factory(BANDWIDTH_METER);
        TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
        //trackSelectionHelper = new TrackSelectionHelper(trackSelector, videoTrackSelectionFactory);
        player = ExoPlayerFactory.newSimpleInstance(getActivity(), trackSelector, new DefaultLoadControl(),
                null, extensionRendererMode);
        player.setPlayWhenReady(false);
        videoView.setPlayer(player);
        //videoView.setOnClickListener(showButtonOnClickLister);
    }
    mediaController = new ECMediaController(getActivity(), new NGEPlayerInterface() {
        @Override
        public boolean isPlaying() {
            if (player != null) {
                return player.getPlaybackState() == ExoPlayer.STATE_READY && player.getPlayWhenReady();
            }
            return false;
        }
    });
    mediaController.setMediaPlayer(playerControl);
    previewImageView = (ImageView)view.findViewById(R.id.ec_video_preview_image);
    previewFrame = (RelativeLayout)view.findViewById(R.id.ec_video_preview_image_frame);
    previewPlayBtn = (ImageButton)view.findViewById(R.id.ec_video_preview_playButton);
    aspectRatioFrame = (FixedAspectRatioFrameLayout) view.findViewById(R.id.ec_video_aspect_ratio_frame);
    countDownCountainer = view.findViewById(R.id.count_down_container);
    countDownTextView = (TextView) view.findViewById(R.id.count_down_text_view);
    countDownProgressBar = (ProgressBar) view.findViewById(R.id.count_down_progressBar);

    loadingView = (ProgressBar)view.findViewById(R.id.next_gen_loading_progress_bar);
    if (loadingView != null){
        loadingView.setBackgroundColor(getResources().getColor(android.R.color.transparent));

    }

    if (countDownCountainer != null)
        countDownCountainer.setVisibility(View.INVISIBLE);
    if (countDownProgressBar != null){
        countDownProgressBar.setMax(COUNT_DOWN_SECONDS);
    }

    if (aspectRatioFrame != null){
        aspectRatioFrame.setAspectRatioPriority(aspectFramePriority);
    }

    if (previewPlayBtn != null) {
        previewPlayBtn.setVisibility(View.GONE);
        previewPlayBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (previewFrame != null)
                    previewFrame.setVisibility(View.GONE);
                playerControl.start();
                NGEAnalyticData.reportEvent(getActivity(), ECVideoViewFragment.this, NGEAnalyticData.AnalyticAction.ACTION_SELECT_VIDEO, selectedAVItem.videoId, null);
            }
        });
    }

    player.addListener(ecVideoViewListener);

    videoView.requestFocus();

    bgImageView = (ImageView) view.findViewById(R.id.ec_video_frame_bg);

    if (bgImageView != null && !StringHelper.isEmpty(bgImageUrl)){
        NextGenGlide.load(getActivity(), bgImageUrl).fitCenter().into(bgImageView);
    }
    if (selectedAVItem != null){
        setAudioVisualItem(selectedAVItem);
    }
}
项目:evercam-android    文件:VideoActivity.java   
private void preparePlayer() {

        if (player == null){

            DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null;

            @SimpleExoPlayer.ExtensionRendererMode int extensionRendererMode =
                    ((EvercamPlayApplication) getApplication()).useExtensionRenderers()
                            ? (false ? SimpleExoPlayer.EXTENSION_RENDERER_MODE_PREFER
                            : SimpleExoPlayer.EXTENSION_RENDERER_MODE_ON)
                            : SimpleExoPlayer.EXTENSION_RENDERER_MODE_OFF;

            TrackSelection.Factory videoTrackSelectionFactory =
                    new AdaptiveVideoTrackSelection.Factory(BANDWIDTH_METER);

            trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

            player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, new DefaultLoadControl(),
                    drmSessionManager, extensionRendererMode);
            player.addListener(this);

            eventLogger = new EventLogger(trackSelector);
            eventLogger.addListener(this);
            player.addListener(eventLogger);
//        player.setAudioDebugListener(eventLogger);
            player.setVideoDebugListener(eventLogger);
            player.setMetadataOutput(eventLogger);

            Uri hlsUrl = Uri.parse(evercamCamera.getHlsUrl());

            MediaSource mediaSource = new HlsMediaSource(hlsUrl, mediaDataSourceFactory, mainHandler, eventLogger);


            boolean haveResumePosition = resumeWindow != C.INDEX_UNSET;
            if (haveResumePosition) {
                player.seekTo(resumeWindow, resumePosition);
            }
            player.prepare(mediaSource, !haveResumePosition, false);

            player.setPlayWhenReady(true);
            player.setVideoSurface(surface);

        }else{
            releasePlayer();
            preparePlayer();
        }


        /*DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null;

        @SimpleExoPlayer.ExtensionRendererMode int extensionRendererMode =
                ((EvercamPlayApplication) getApplication()).useExtensionRenderers()
                        ? (false ? SimpleExoPlayer.EXTENSION_RENDERER_MODE_PREFER
                        : SimpleExoPlayer.EXTENSION_RENDERER_MODE_ON)
                        : SimpleExoPlayer.EXTENSION_RENDERER_MODE_OFF;

        TrackSelection.Factory videoTrackSelectionFactory =
                new AdaptiveVideoTrackSelection.Factory(BANDWIDTH_METER);

        trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);

        player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, new DefaultLoadControl(),
                drmSessionManager, extensionRendererMode);
        player.addListener(this);
        eventLogger = new EventLogger(trackSelector);
        eventLogger.addListener(this);
        player.addListener(eventLogger);
//        player.setAudioDebugListener(eventLogger);
        player.setVideoDebugListener(eventLogger);
        player.setMetadataOutput(eventLogger);
        Uri hlsUrl = Uri.parse(evercamCamera.getHlsUrl());
        MediaSource mediaSource = new HlsMediaSource(hlsUrl, mediaDataSourceFactory, mainHandler, eventLogger);

        player.prepare(mediaSource);
        player.setPlayWhenReady(true);
        player.setVideoSurface(surface);*/
    }