/*** * 创建实例播放实例,并不开始缓冲 **/ private SimpleExoPlayer createFullPlayer() { TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); BufferingLoadControl loadControl = new BufferingLoadControl(); if (null == modelType) { setDefaultLoadModel(); } else { loadControl.setListener(new LoadListener() { @Override public void onProgress(long pro) { getPlayerViewListener().showNetSpeed(String.valueOf(pro) + "%"); } }); } DefaultRenderersFactory rf = new DefaultRenderersFactory(activity, drmSessionManager, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(rf, trackSelector, loadControl); player.setPlaybackParameters(playbackParameters); getPlayerViewListener().setPlayer(player); return player; }
@Override public IBinder onBind(final Intent intent) { bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "SyncPlayer"), bandwidthMeter); extractorsFactory = new DefaultExtractorsFactory(); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector, loadControl); mMediaPlayer = player; setCompletionListener(); nbuilder.setSmallIcon(R.mipmap.ic_launcher); return mBinder; }
protected void initPlayer() { // 1. Create a default TrackSelector mMainHandler = new Handler(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); mTrackSelectionHelper = new TrackSelectionHelper(this, mTrackSelector,videoTrackSelectionFactory); // 3. Create the mTubiExoPlayer mTubiExoPlayer = ExoPlayerFactory.newSimpleInstance(this, mTrackSelector); mEventLogger = new EventLogger(mTrackSelector); mTubiExoPlayer.addListener(mEventLogger); mTubiExoPlayer.setAudioDebugListener(mEventLogger); mTubiExoPlayer.setVideoDebugListener(mEventLogger); mTubiExoPlayer.setMetadataOutput(mEventLogger); mTubiPlayerView.setPlayer(mTubiExoPlayer, this); mTubiPlayerView.setMediaModel(mediaModel,true); mTubiPlayerView.setTrackSelectionHelper(mTrackSelectionHelper); }
private void initializePlayer() { if (player == null) { // a factory to create an AdaptiveVideoTrackSelection TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); // using a DefaultTrackSelector with an adaptive video selection factory player = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this), new DefaultTrackSelector(adaptiveTrackSelectionFactory), new DefaultLoadControl()); player.addListener(componentListener); player.addVideoDebugListener(componentListener); player.addAudioDebugListener(componentListener); playerView.setPlayer(player); player.setPlayWhenReady(playWhenReady); player.seekTo(currentWindow, playbackPosition); } MediaSource mediaSource = buildMediaSource(Uri.parse(getString(R.string.media_url_dash))); player.prepare(mediaSource, true, false); }
private SimpleExoPlayer setupPlayer(){ Log.d(TAG,"Setting up Player."); videoView.setKeepScreenOn(true); mUserAgent = Util.getUserAgent(getContext(), getResources().getString(R.string.app_name)); AdaptiveTrackSelection.Factory trackSelectorFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); DefaultTrackSelector trackSelector = new DefaultTrackSelector(trackSelectorFactory); LoadControl loadControl = new DefaultLoadControl(); DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(getContext(), null, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF); exoPlayer = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector, loadControl); MyListener listener = new MyListener(exoPlayer, this); exoPlayer.addVideoListener(listener); exoPlayer.addListener(listener); exoPlayer.setPlayWhenReady(mPlaybackState); exoPlayer.prepare(buildMediaSource(Uri.parse(mRecording.getRecordingUrl()),"")); return exoPlayer; }
@Override public void prepareAsync() throws IllegalStateException { TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); DefaultTrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); mInternalMediaPlayer = InternalExoPlayer.newInstance(mAppContext, trackSelector); mEventListener = new ExoEventListener(); mInternalMediaPlayer.addListener(mEventListener); mVideoListener = new ExoVideoListener(); mInternalMediaPlayer.addVideoListener(mVideoListener); MediaSource mediaSource = buildMediaSource(mUri, mHeaders); mInternalMediaPlayer.setVideoSurface(mSurface); mInternalMediaPlayer.prepare(mediaSource); notifyOnPrepared(); }
private void setExoViewSource(@NonNull MasterSecret masterSecret, @NonNull VideoSlide videoSource) throws IOException { BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); exoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl); exoView.setPlayer(exoPlayer); DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(getContext(), "GenericUserAgent", null); AttachmentDataSourceFactory attachmentDataSourceFactory = new AttachmentDataSourceFactory(getContext(), masterSecret, defaultDataSourceFactory, null); ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); MediaSource mediaSource = new ExtractorMediaSource(videoSource.getUri(), attachmentDataSourceFactory, extractorsFactory, null, null); exoPlayer.prepare(mediaSource); exoPlayer.setPlayWhenReady(true); }
private void setupExoPlayer() { TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); exoPlayer = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(this), new DefaultTrackSelector(adaptiveTrackSelectionFactory), new DefaultLoadControl()); pvVideoPreview.setPlayer(exoPlayer); exoPlayer.setPlayWhenReady(true); Uri uri = Uri.parse("asset:///sample_video.mp4"); MediaSource mediaSource = createMediaSource(this, uri); LoopingMediaSource loopingMediaSource = new LoopingMediaSource(mediaSource); exoPlayer.prepare(loopingMediaSource, true, false); }
private void initExoPlayer(MediaSource sampleSource) { if (exoPlayer == null) { TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); // 2. Create the player exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector); } exoPlayer.prepare(sampleSource); exoPlayer.setVideoSurfaceView(svPlayer); exoPlayer.setPlayWhenReady(true); initMediaControls(); }
private void initializePlayer() { simpleExoPlayerView.requestFocus(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(this, trackSelector); simpleExoPlayerView.setPlayer(player); MediaSource[] mediaSources = new MediaSource[videos.size()]; for (int i = 0; i < videos.size(); i++) { mediaSources[i] = buildMediaSource(Uri.parse(videos.get(i).videoUrl)); } MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0] : new ConcatenatingMediaSource(mediaSources); player.prepare(mediaSource); }
public ExoMediaPlayer(@NonNull Context context) { this.context = context; bufferRepeater.setRepeaterDelay(BUFFER_REPEAT_DELAY); bufferRepeater.setRepeatListener(new BufferRepeatListener()); mainHandler = new Handler(); ComponentListener componentListener = new ComponentListener(); RendererProvider rendererProvider = new RendererProvider(context, mainHandler, componentListener, componentListener, componentListener, componentListener); rendererProvider.setDrmSessionManager(generateDrmSessionManager()); renderers = rendererProvider.generate(); adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory); LoadControl loadControl = ExoMedia.Data.loadControl != null ? ExoMedia.Data.loadControl : new DefaultLoadControl(); player = ExoPlayerFactory.newInstance(renderers.toArray(new Renderer[renderers.size()]), trackSelector, loadControl); player.addListener(this); }
private void initializePlayer() { BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); mPlayer = ExoPlayerFactory.newSimpleInstance(getActivity(), mTrackSelector); mPlayerAdapter = new LeanbackPlayerAdapter(getActivity(), mPlayer, UPDATE_DELAY); mPlaylistActionListener = new PlaylistActionListener(mPlaylist); mPlayerGlue = new VideoPlayerGlue(getActivity(), mPlayerAdapter, mPlaylistActionListener); mPlayerGlue.setHost(new VideoFragmentGlueHost(this)); mPlayerGlue.playWhenPrepared(); play(mVideo); ArrayObjectAdapter mRowsAdapter = initializeRelatedVideosRow(); setAdapter(mRowsAdapter); }
private static SimpleExoPlayer createPlayer(Context context) { BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); return ExoPlayerFactory.newSimpleInstance(context.getApplicationContext(), trackSelector); }
/** * 播放启动视频 */ private void startPlayer() { // 0. set player view playerView = (SimpleExoPlayerView) findViewById(R.id.playerView); playerView.setUseController(false); playerView.getKeepScreenOn(); playerView.setResizeMode(RESIZE_MODE_FILL); // 1. Create a default TrackSelector TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); // 2. Create a default LoadControl loadControl = new DefaultLoadControl(); // 3. Create the mPlayer mPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl); mPlayer.addListener(this); // 4. set player playerView.setPlayer(mPlayer); mPlayer.setPlayWhenReady(true); // 5. prepare to play File file = new File(Constants.FILE_VIDEO_FLODER, "jcode.mp4"); if (file.isFile() && file.exists()) { mUri = Uri.fromFile(file); } else { Toast.makeText(this,"文件未找到",Toast.LENGTH_SHORT).show(); return; } ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, "UserAgent"); videoSource = new ExtractorMediaSource(mUri, dataSourceFactory, extractorsFactory, null, null); // 6. ready to play mPlayer.prepare(videoSource); }
private void initializePlayer() { if (player == null) { // a factory to create an AdaptiveVideoTrackSelection TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); // let the factory create a player instance with default components player = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this), new DefaultTrackSelector(adaptiveTrackSelectionFactory), new DefaultLoadControl()); playerView.setPlayer(player); player.setPlayWhenReady(playWhenReady); player.seekTo(currentWindow, playbackPosition); } MediaSource mediaSource = buildMediaSource(Uri.parse(getString(R.string.media_url_dash))); player.prepare(mediaSource, true, false); }
public PlayerController(Context context) { this.bandwidthMeter = new DefaultBandwidthMeter(); this.loadControl = new DefaultLoadControl(); this.extractorsFactory = new DefaultExtractorsFactory(); this.trackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); this.dataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context.getApplicationContext(), TAG_NAME), (TransferListener<? super DataSource>) bandwidthMeter); this.trackSelector = new DefaultTrackSelector(trackSelectionFactory); this.player = ExoPlayerFactory.newSimpleInstance(context, this.trackSelector, this.loadControl); this.playerView = new PlayerView(context,this.player); }
private ExoPlayerInstance() { this.context = ExpressApplication.getApplication(); DefaultBandwidthMeter defaultBandwidthMeter = new DefaultBandwidthMeter(); mainHandler = new Handler(); defaultExtractorsFactory = new DefaultExtractorsFactory(); mediaDataSourceFactory = new DefaultDataSourceFactory(context, defaultBandwidthMeter, new OkHttpDataSourceFactory(new OkHttpClient.Builder().build(), Util.getUserAgent(context, "Tumbviewer"), defaultBandwidthMeter, CacheControl.FORCE_NETWORK)); TrackSelection.Factory factory = new AdaptiveTrackSelection.Factory(defaultBandwidthMeter); trackSelector = new DefaultTrackSelector(factory); }
private SimpleExoPlayer createFullPlayer() { TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(playerView.getContext()), trackSelector, loadControl); player.setPlayWhenReady(true); player.prepare(mediaSourceBuilder.getMediaSource(false)); player.addListener(eventListener); return player; }
private SimpleExoPlayer createFullPlayer() { TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); LoadControl loadControl = new DefaultLoadControl(); SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(playerView.getContext()), trackSelector, loadControl); player.setPlayWhenReady(true); player.prepare(mediaSourceBuilder.getMediaSource(false)); player.addListener(this); return player; }
private void initExoPlayer() { DefaultBandwidthMeter bwMeter = new DefaultBandwidthMeter(); AdaptiveTrackSelection.Factory trackFactory = new AdaptiveTrackSelection.Factory(bwMeter); DefaultTrackSelector trackSelector = new DefaultTrackSelector(trackFactory); player = ExoPlayerFactory.newSimpleInstance(this, trackSelector); videoView.setPlayer(player); DataSource.Factory dsFactory = new DefaultDataSourceFactory(getBaseContext(), Util.getUserAgent(this, "Traxy"), bwMeter); ExtractorsFactory exFactory = new DefaultExtractorsFactory(); Uri mediaUri = Uri.parse(entry.getUrl()); MediaSource videoSource = new ExtractorMediaSource(mediaUri, dsFactory, exFactory, null, null); player.prepare(videoSource); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setSupportActionBar(toolbar); window = getWindow(); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); } channelList = new SortableJsonChannelList(this); // player DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, getString(R.string.app_name)), bandwidthMeter); player = ExoPlayerFactory.newSimpleInstance(this, trackSelector); player.addListener(bufferingHandler); player.addListener(videoErrorHandler); videoView.setPlayer(player); // pager channelDetailAdapter = new ChannelDetailAdapter( getSupportFragmentManager(), channelList, onItemChangedListener); viewPager.setAdapter(channelDetailAdapter); viewPager.addOnPageChangeListener(onPageChangeListener); viewPager.setOnClickListener(view -> mContentView.performClick()); parseIntent(getIntent()); }
@Override public void prepareAsync() throws IllegalStateException { if (mInternalPlayer != null) throw new IllegalStateException("can't prepare a prepared player"); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter()); mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); mEventLogger = new EventLogger(mTrackSelector); boolean preferExtensionDecoders = true; boolean useExtensionRenderers = true;//是否开启扩展 @DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode = useExtensionRenderers ? (preferExtensionDecoders ? DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER : DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON) : DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF; renderersFactory = new DefaultRenderersFactory(mAppContext, null, extensionRendererMode); DefaultLoadControl loadControl = new DefaultLoadControl(); mInternalPlayer = new SimpleExoPlayer2(renderersFactory, mTrackSelector, loadControl); mInternalPlayer.addListener(this); mInternalPlayer.setVideoDebugListener(this); mInternalPlayer.setAudioDebugListener(this); mInternalPlayer.addListener(mEventLogger); if (mSpeedPlaybackParameters != null) { mInternalPlayer.setPlaybackParameters(mSpeedPlaybackParameters); } if (mSurface != null) mInternalPlayer.setVideoSurface(mSurface); mInternalPlayer.prepare(mMediaSource); mInternalPlayer.setPlayWhenReady(false); }
/**--------------------- 创建SimpleExoPlayer ----------------------------**/ private void initExoPlayer() { mMediaDataSourceFactory = buildDataSourceFactory(true); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); mTrackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); mEventLogger = new EventLogger(mTrackSelector); mMainHandler = new Handler(Looper.getMainLooper()); DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(mContext, null, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_OFF); mExoPlayer = ExoPlayerFactory.newSimpleInstance(renderersFactory, mTrackSelector); mExoPlayer.addListener(mEventLogger); mExoPlayer.setAudioDebugListener(mEventLogger); mExoPlayer.setVideoDebugListener(mEventLogger); mExoPlayer.setMetadataOutput(mEventLogger); mExoPlayer.setTextOutput(null); mExoPlayer.setVideoListener(null); mExoPlayer.removeListener(this); mExoPlayer.setVideoTextureView(null); mExoPlayer.setVideoListener(this); mExoPlayer.addListener(this); mExoPlayer.setTextOutput(this); }
private void initializePlayer() { simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.player_view); simpleExoPlayerView.requestFocus(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(this, trackSelector); simpleExoPlayerView.setPlayer(player); player.setPlayWhenReady(shouldAutoPlay); /* MediaSource mediaSource = new HlsMediaSource(Uri.parse("https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8"), mediaDataSourceFactory, mainHandler, null);*/ DefaultExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); MediaSource mediaSource = new ExtractorMediaSource(Uri.parse("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"), mediaDataSourceFactory, extractorsFactory, null, null); player.prepare(mediaSource); ivHideControllerButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { simpleExoPlayerView.hideController(); } }); }
public void init(Context context, SimpleExoPlayerView simpleExoPlayerView) { // Create a default track selector. BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); // Create a player instance. player = ExoPlayerFactory.newSimpleInstance(context, trackSelector); // Bind the player to the view. simpleExoPlayerView.setPlayer(player); // Produces DataSource instances through which media data is loaded. DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context, context.getString(R.string.application_name))); // This is the MediaSource representing the content media (i.e. not the ad). String contentUrl = context.getString(R.string.content_url); MediaSource contentMediaSource = new ExtractorMediaSource.Factory(dataSourceFactory) .createMediaSource(Uri.parse(contentUrl)); // Compose the content media source into a new AdsMediaSource with both ads and content. MediaSource mediaSourceWithAds = new AdsMediaSource( contentMediaSource, /* adMediaSourceFactory= */ this, adsLoader, simpleExoPlayerView.getOverlayFrameLayout(), /* eventHandler= */ null, /* eventListener= */ null); // Prepare the player with the source. player.seekTo(contentPosition); player.prepare(mediaSourceWithAds); player.setPlayWhenReady(true); }
@Override public void onCreate() { Log.d("MediaService", "OnCreate"); // Load controls BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoFactory); LoadControl loadControl = new DefaultLoadControl(); // Create Player player = ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector, loadControl); }
private void initPlayer(String url) { // 1.创建一个默认TrackSelector,测量播放过程中的带宽。 如果不需要,可以为null。 DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); //从MediaSource中选出media提供给可用的Render S来渲染,在创建播放器时被注入 TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); // 2.创建一个默认的LoadControl //Create a default LoadControl 控制MediaSource缓存media DefaultLoadControl loadControl = new DefaultLoadControl(); // BufferingLoadControl bufferingLoadControl = new BufferingLoadControl(); //生成加载媒体数据的DataSource实例。 // dataSourceFactory = new DefaultDataSourceFactory(this, // Util.getUserAgent(this, "aitrip"), bandwidthMeter); //自定义解密工厂 aitripFactory = new AitripDataSourceFactory(this, Util.getUserAgent(this, "aitrip"), bandwidthMeter); extractorsFactory = new DefaultExtractorsFactory(); // factory = new DiyExtractorsFactory(); FileDataSource fileDataSource = new FileDataSource(); //test mp3 // url = "https://storage.googleapis.com/exoplayer-test-media-0/play.mp3"; // MediaSource代表要播放的媒体。 videoSource = new ExtractorMediaSource(Uri.parse(url), aitripFactory, extractorsFactory, null, null); // 3.创建播放器 player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl); //SimpleExoPlayerView simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.exo_player); //设置监听器 player.addListener(eventListener); //装载多个资源 MediaSource[] mediaSources = new MediaSource[1]; // mediaSources[0] = buildMediaSource(Uri.parse(huai), ""); // mediaSources[1] = buildMediaSource(Uri.parse(deng), ""); mediaSources[0] = buildMediaSource(Uri.parse(deng), ""); // mediaSources[2] = buildMediaSource(playerUri, ""); // mediaSources[3] = buildMediaSource(Uri.parse(deng), ""); ConcatenatingMediaSource mediaSource = new ConcatenatingMediaSource(mediaSources); //设置资源 player.prepare(mediaSource); window = new Timeline.Window(); }
private void preparePlayer() { setStatus(STATUS_PREPARING); BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(trackSelectionFactory); exoPlayer = ExoPlayerFactory.newSimpleInstance(app, trackSelector); // DefaultBandwidthMeter bandwidthMeterA = new DefaultBandwidthMeter(); // Produces DataSource instances through which media data is loaded. // DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "exoplayer2example"), bandwidthMeterA); // DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(App.getInstance(), Util.getUserAgent(App.getInstance(), "exoplayer2example"), bandwidthMeterA); Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyConfig.getAddress(), proxyConfig.getPort())); if (proxyConfig.isAuthEnabled()) { Authenticator authenticator = new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(proxyConfig.getUser(), proxyConfig.getPass().toCharArray()); } }; Authenticator.setDefault(authenticator); } else { Authenticator.setDefault(null); } String userAgent = Util.getUserAgent(app, "Phoenix-for-VK"); CustomHttpDataSourceFactory factory = new CustomHttpDataSourceFactory(userAgent, proxy); // Produces Extractor instances for parsing the media data. ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); // This is the MediaSource representing the media to be played: // FOR SD CARD SOURCE: // MediaSource videoSource = new ExtractorMediaSource(mp4VideoUri, dataSourceFactory, extractorsFactory, null, null); // FOR LIVESTREAM LINK: String url = playingEntry.getAudio().getLinkMp3(); MediaSource mediaSource = new ExtractorMediaSource(Uri.parse(url), factory, extractorsFactory, null, null); exoPlayer.setRepeatMode(Player.REPEAT_MODE_OFF); exoPlayer.addListener(new ExoEventAdapter() { @Override public void onPlayerStateChanged(boolean b, int i) { onInternalPlayerStateChanged(i); } @Override public void onPlayerError(ExoPlaybackException error) { onExoPlayerException(error); } }); exoPlayer.setPlayWhenReady(supposedToBePlaying); exoPlayer.prepare(mediaSource); }
private void setupAdPlayer() { TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER_AD); trackSelector_ad = new DefaultTrackSelector(adaptiveTrackSelectionFactory); adPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector_ad); }
/** * Initializes the player. */ public void Initialize(final BA ba, String EventName) { eventName = EventName.toLowerCase(BA.cul); BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(BA.applicationContext, trackSelector); player.addListener(new Player.EventListener() { @Override public void onLoadingChanged(boolean isLoading) { } @Override public void onPlayerError(ExoPlaybackException error) { ba.raiseEvent(SimpleExoPlayerWrapper.this, eventName + "_error", String.valueOf(error.getCause())); } @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { if (playbackState != currentState) { currentState = playbackState; if (currentState == Player.STATE_ENDED) ba.raiseEvent(SimpleExoPlayerWrapper.this, eventName + "_complete"); else if (currentState == Player.STATE_READY) ba.raiseEvent(SimpleExoPlayerWrapper.this, eventName + "_ready"); } } @Override public void onPositionDiscontinuity() { } @Override public void onTimelineChanged(Timeline timeline, Object manifest) { } @Override public void onPlaybackParametersChanged( PlaybackParameters playbackParameters) { // TODO Auto-generated method stub } @Override public void onRepeatModeChanged(int repeatMode) { } @Override public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) { ba.raiseEventFromUI(SimpleExoPlayerWrapper.this, eventName + "_trackchanged"); } }); }
public void showImagePopup(Point p, final String uri) { Activity context = MainActivity.this; //COMPLETED solving video problem final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.image_popup_layout); dialog.show(); WindowManager.LayoutParams lp = new WindowManager.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp.copyFrom(dialog.getWindow().getAttributes()); dialog.getWindow().setAttributes(lp); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); dialog.getWindow().setDimAmount(0); // Getting a reference to Close button, and close the popup when clicked. FloatingActionButton close = (FloatingActionButton) dialog.findViewById(R.id.close_image_popup_button); ImageView statusImage = (ImageView) dialog.findViewById(R.id.full_status_image_view); final SimpleExoPlayerView simpleExoPlayerView = dialog.findViewById(R.id.full_status_video_view); final SimpleExoPlayer player; if (uri.endsWith(".jpg")) { GlideApp.with(context).load(uri).fitCenter().into(statusImage); } else if (uri.endsWith(".mp4")) { statusImage.setVisibility(View.GONE); simpleExoPlayerView.setVisibility(View.VISIBLE); Uri myUri = Uri.parse(uri); // initialize Uri here // 1. Create a default TrackSelector BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); // 2. Create a default LoadControl LoadControl loadControl = new DefaultLoadControl(); // 3. Create the player player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl); //Set media controller simpleExoPlayerView.setUseController(true); simpleExoPlayerView.requestFocus(); // Bind the player to the view. simpleExoPlayerView.setPlayer(player); //Measures bandwidth during playback. Can be null if not required. DefaultBandwidthMeter bandwidthMeterA = new DefaultBandwidthMeter(); //Produces DataSource instances through which media data is loaded. DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(this, Util. getUserAgent(this, "exoplayer2example"), bandwidthMeterA); //Produces Extractor instances for parsing the media data. ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); MediaSource videoSource = new ExtractorMediaSource(myUri, dataSourceFactory, extractorsFactory, null, null); player.prepare(videoSource); player.setPlayWhenReady(true); //run file/link when ready to play. dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialogInterface) { player.release(); } }); } close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // popup.dismiss(); dialog.cancel(); } }); }
private void initPlayer() { // Produces DataSource instances through which media data is loaded. DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, getString(R.string.app_name)), null); // Produces Extractor instances for parsing the media data. ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); // This is the MediaSource representing the media to be played. MediaSource videoSource = new ExtractorMediaSource(videoUri, dataSourceFactory, extractorsFactory, null, null); DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this); // Create the player player = ExoPlayerFactory.newSimpleInstance(renderersFactory, new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(null)), new DefaultLoadControl()); // Bind the player to the view. SimpleExoPlayerView simpleExoPlayerView = findViewById(R.id.simpleExoPlayerView); simpleExoPlayerView.setPlayer(player); // Prepare the player with the source. player.prepare(videoSource); player.setRepeatMode(Player.REPEAT_MODE_ONE); player.setPlayWhenReady(true); final ImageButton playPause = findViewById(R.id.play_pause); player.addListener(new SimpleEventListener() { @Override public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { //update PlayPause-Button if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (player.getPlayWhenReady()) { playPause.setImageResource(R.drawable.play_to_pause_avd); } else { playPause.setImageResource(R.drawable.pause_to_play_avd); } Drawable d = playPause.getDrawable(); if (d instanceof Animatable) { ((Animatable) d).start(); } } else { if (player.getPlayWhenReady()) { playPause.setImageResource(R.drawable.ic_pause_white_24dp); } else { playPause.setImageResource(R.drawable.ic_play_arrow_white_24dp); } } } }); }
protected SimpleExoPlayer newMediaPlayer(Context context, String url, int type) { return ExoPlayerFactory.newSimpleInstance(context, new DefaultTrackSelector(new AdaptiveTrackSelection.Factory(BANDWIDTH_METER))); }
ExoPlayerTwoImpl create(Context context, DrmSessionCreator drmSessionCreator, boolean downgradeSecureDecoder) { DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(context, "user-agent", bandwidthMeter); MediaSourceFactory mediaSourceFactory = new MediaSourceFactory(defaultDataSourceFactory, handler); TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); DefaultTrackSelector trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory); MediaCodecSelector mediaCodecSelector = downgradeSecureDecoder ? SecurityDowngradingCodecSelector.newInstance() : MediaCodecSelector.DEFAULT; ExoPlayerTrackSelector exoPlayerTrackSelector = ExoPlayerTrackSelector.newInstance(trackSelector); FixedTrackSelection.Factory trackSelectionFactory = new FixedTrackSelection.Factory(); ExoPlayerAudioTrackSelector exoPlayerAudioTrackSelector = new ExoPlayerAudioTrackSelector(exoPlayerTrackSelector, trackSelectionFactory); ExoPlayerVideoTrackSelector exoPlayerVideoTrackSelector = new ExoPlayerVideoTrackSelector(exoPlayerTrackSelector, trackSelectionFactory); ExoPlayerSubtitleTrackSelector exoPlayerSubtitleTrackSelector = new ExoPlayerSubtitleTrackSelector( exoPlayerTrackSelector, trackSelectionFactory ); ExoPlayerCreator exoPlayerCreator = new ExoPlayerCreator(context, trackSelector); RendererTypeRequesterCreator rendererTypeRequesterCreator = new RendererTypeRequesterCreator(); ExoPlayerFacade exoPlayerFacade = new ExoPlayerFacade( mediaSourceFactory, exoPlayerAudioTrackSelector, exoPlayerSubtitleTrackSelector, exoPlayerVideoTrackSelector, exoPlayerCreator, rendererTypeRequesterCreator); PlayerListenersHolder listenersHolder = new PlayerListenersHolder(); ExoPlayerForwarder exoPlayerForwarder = new ExoPlayerForwarder(); LoadTimeout loadTimeout = new LoadTimeout(new SystemClock(), handler); Heart heart = Heart.newInstance(handler); return new ExoPlayerTwoImpl( exoPlayerFacade, listenersHolder, exoPlayerForwarder, loadTimeout, heart, drmSessionCreator, mediaCodecSelector ); }