@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); shouldAutoPlay = true; clearResumePosition(); mediaDataSourceFactory = buildDataSourceFactory(true); mainHandler = new Handler(); if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) { CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER); } setContentView(R.layout.player_activity); View rootView = findViewById(R.id.root); rootView.setOnClickListener(this); debugRootView = (LinearLayout) findViewById(R.id.controls_root); debugTextView = (TextView) findViewById(R.id.debug_text_view); retryButton = (Button) findViewById(R.id.retry_button); retryButton.setOnClickListener(this); simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.player_view); simpleExoPlayerView.setControllerVisibilityListener(this); simpleExoPlayerView.requestFocus(); }
public SimpleExoPlayer prepareExoPlayerForUri( int playerKey, @NonNull Context context, @NonNull Uri uri, @NonNull SimpleExoPlayerView simpleExoPlayerView, int currentWindow, boolean playWhenReady, long playbackPosition) { SimpleExoPlayer simpleExoPlayer = playersInUse.get(playerKey); if (simpleExoPlayer == null) { simpleExoPlayer = setUpMediaPlayer(context); simpleExoPlayerView.setPlayer(simpleExoPlayer); simpleExoPlayer.setPlayWhenReady(playWhenReady); simpleExoPlayer.seekTo(currentWindow, playbackPosition); MediaSource mediaSource = setUpMediaSource(context, uri); simpleExoPlayer.prepare(mediaSource, true, false); playersInUse.put(playerKey, simpleExoPlayer); } else { simpleExoPlayer.seekTo(currentWindow, playbackPosition); simpleExoPlayer.setPlayWhenReady(playWhenReady); } return simpleExoPlayer; }
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = getIntent(); Uri uri = intent.getParcelableExtra("uri"); long playerPosition = intent.getLongExtra("position", C.TIME_UNSET); int playerWindow = intent.getIntExtra("windowIndex", 0); boolean rotation = intent.getBooleanExtra("rotation", false); if (rotation) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } playerInstance = ExoPlayerInstance.getInstance(); SimpleExoPlayer player = playerInstance.getPlayer(); setContentView(R.layout.activity_video_player); playerView = (SimpleExoPlayerView) findViewById(R.id.player_view); playerView.setPlayer(player); if (playerPosition == C.TIME_UNSET) { player.seekToDefaultPosition(playerWindow); } else { player.seekTo(playerWindow, playerPosition); } playerInstance.prepare(uri, null); setVolumeControlStream(AudioManager.STREAM_MUSIC); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SimpleExoPlayerView playerView = findViewById(R.id.player_view); previewTimeBar = playerView.findViewById(R.id.exo_progress); previewTimeBarLayout = findViewById(R.id.previewSeekBarLayout); previewTimeBarLayout.setTintColorResource(R.color.colorPrimary); previewTimeBar.addOnPreviewChangeListener(this); exoPlayerManager = new ExoPlayerManager(playerView, previewTimeBarLayout, (ImageView) findViewById(R.id.imageView), getString(R.string.url_thumbnails)); exoPlayerManager.play(Uri.parse(getString(R.string.url_dash))); previewTimeBarLayout.setPreviewLoader(exoPlayerManager); requestFullScreenIfLandscape(); }
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) @Override public void onServiceConnected(ComponentName className, IBinder service) { Log.d("ServiceConnection","connected"); MediaService.LocalBinder binder = (MediaService.LocalBinder) service; MediaService mediaService = binder.getService(); player = mediaService.setUpPlayer(url); Log.d("ServiceConnection", player.toString()); // ExoPlayer Views SimpleExoPlayerView mVideoView = findViewById(R.id.media_player); mVideoView.setPlayer(player); mVideoView.requestFocus(); if (path.contains(".mp3") || path.contains("m4a")) { // mVideoView.setControllerShowTimeoutMs(-1); ImageView artwork = findViewById(R.id.exo_thumbnail); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { artwork.setImageDrawable(getApplicationContext().getDrawable(R.drawable.logo)); } else { artwork.setImageDrawable(getResources().getDrawable(R.drawable.logo)); } } else { // fullscreen for video hideStatusBar(); } }
@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); } }
@Hide @Override public void _initialize(final BA ba, Object activityClass, String EventName) { final SimpleExoPlayerView view = new SimpleExoPlayerView(ba.context); final String eventName = EventName.toLowerCase(BA.cul); setObject(view); innerInitialize(ba, eventName, true); }
/** * 播放启动视频 */ 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); }
public PlayerView(Context context, SimpleExoPlayer player) { super(context); simpleExoPlayerView = new SimpleExoPlayerView(context); progressBar = new ProgressBar(context); textView = new TextView(context); textView.setX(40); textView.setY(20); textView.setTextColor(Color.parseColor("#FFFFFF")); textView.setTextSize(16); textView.setText("By Herudi"); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(100,100); params.addRule(RelativeLayout.CENTER_IN_PARENT); simpleExoPlayerView.setLayoutParams(new SimpleExoPlayerView.LayoutParams( SimpleExoPlayerView.LayoutParams.MATCH_PARENT, SimpleExoPlayerView.LayoutParams.MATCH_PARENT )); setLayoutParams(new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT )); setBackgroundColor(ContextCompat.getColor(context, android.R.color.black)); addView(simpleExoPlayerView); addView(textView); addView(progressBar,params); simpleExoPlayerView.setUseController(true); simpleExoPlayerView.requestFocus(); simpleExoPlayerView.setPlayer(player); simpleExoPlayerView.setControllerVisibilityListener(new PlaybackControlView.VisibilityListener() { @Override public void onVisibilityChange(int visibility) { if (visibility==0){ textView.setVisibility(VISIBLE); }else { textView.setVisibility(GONE); } } }); }
public ExoPlayerManager(SimpleExoPlayerView playerView, PreviewTimeBarLayout previewTimeBarLayout, ImageView imageView, String thumbnailsUrl) { this.playerView = playerView; this.imageView = imageView; this.previewTimeBarLayout = previewTimeBarLayout; this.mediaSourceBuilder = new ExoPlayerMediaSourceBuilder(playerView.getContext()); this.thumbnailsUrl = thumbnailsUrl; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SimpleExoPlayerView playerView = findViewById(R.id.player_view); SimpleExoPlayerView previewPlayerView = findViewById(R.id.previewPlayerView); previewTimeBar = playerView.findViewById(R.id.exo_progress); previewTimeBarLayout = findViewById(R.id.previewSeekBarLayout); previewTimeBarLayout.setTintColorResource(R.color.colorPrimary); previewTimeBar.addOnPreviewChangeListener(this); exoPlayerManager = new ExoPlayerManager(playerView, previewPlayerView, previewTimeBarLayout); exoPlayerManager.play(Uri.parse(getString(R.string.url_hls))); previewTimeBarLayout.setup(exoPlayerManager); View view = previewPlayerView.getVideoSurfaceView(); if (view instanceof SurfaceView) { SurfaceView surfaceView = (SurfaceView) view; surfaceView.setZOrderMediaOverlay(true); surfaceView.setZOrderOnTop(true); surfaceView.setVisibility(View.INVISIBLE); } requestFullScreenIfLandscape(); }
public ExoPlayerManager(SimpleExoPlayerView playerView, SimpleExoPlayerView previewPlayerView, PreviewTimeBarLayout previewTimeBarLayout) { this.playerView = playerView; this.previewPlayerView = previewPlayerView; this.previewTimeBarLayout = previewTimeBarLayout; this.mediaSourceBuilder = new ExoPlayerMediaSourceBuilder(playerView.getContext()); }
@Override public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) { super.onPictureInPictureModeChanged(isInPictureInPictureMode); SimpleExoPlayerView simpleExoPlayerView = findViewById(R.id.simpleExoPlayerView); if (isInPictureInPictureMode) { // Hide the controls in picture-in-picture mode. simpleExoPlayerView.hideController(); } else { // Restore the playback UI based on the playback status. simpleExoPlayerView.showController(); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SimpleExoPlayerView playerView = findViewById(R.id.simple_exoplayer_view); String videoUrl = "http://docs.evostream.com/sample_content/assets/bunny.mp4"; getLifecycle().addObserver(new VideoPlayerComponent(getApplicationContext(), playerView, videoUrl)); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); shouldAutoPlay = true; mediaDataSourceFactory = buildDataSourceFactory(true); mainHandler = new Handler(); window = new Timeline.Window(); if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) { CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER); } setContentView(R.layout.player_activity_v2); // View rootView = findViewById(root); simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.player_view); // simpleExoPlayerView.setControllerVisibilityListener(this); simpleExoPlayerView.requestFocus(); /**不使用ExoPlayer自带的mediaController**/ simpleExoPlayerView.setUseController(false); controller = (MediaControlView) findViewById(R.id.player_control); controller.setVisibilityListener(new MediaControlView.VisibilityListener() { @Override public void onVisibilityChange(int visibility) { } }); EventBus.getDefault().register(this); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_playlist); createDummyList(); simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.player_view); mainHandler = new Handler(); bandwidthMeter = new DefaultBandwidthMeter(); mediaDataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this,null)); }
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(); } }); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); shouldAutoPlay = true; mediaDataSourceFactory = buildDataSourceFactory(true); mainHandler = new Handler(); window = new Timeline.Window(); if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) { CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER); } setContentView(R.layout.player_activity); View rootView = findViewById(R.id.root); rootView.setOnClickListener(this); debugRootView = (LinearLayout) findViewById(R.id.controls_root); debugTextView = (TextView) findViewById(R.id.debug_text_view); retryButton = (Button) findViewById(R.id.retry_button); retryButton.setOnClickListener(this); simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.player_view); simpleExoPlayerView.setControllerVisibilityListener(this); simpleExoPlayerView.requestFocus(); String title = getIntent().getStringExtra(PLAYER_TITLE); setTitle(title); tracker.setScreenName("播放器: " + title); tracker.send(new HitBuilders.ScreenViewBuilder().build()); }
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); }
/** * Instantiates a new Base view. * * @param context the context * @param attrs the attrs * @param defStyleAttr the def style attr */ public BaseView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); activity = (Activity) context; LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); playerView = new SimpleExoPlayerView(getContext(), attrs); addView(playerView, params); int userWatermark = 0; int replayId = R.layout.simple_exo_play_replay; int errorId = R.layout.simple_exo_play_error; int playerHintId = R.layout.simple_exo_play_btn_hint; int defaultArtworkId = 0; int loadId = R.layout.simple_exo_play_load; int videoProgressId = R.layout.simple_exo_video_progress_dialog; int audioId = R.layout.simple_video_audio_brightness_dialog; int brightnessId = R.layout.simple_video_audio_brightness_dialog; int preViewLayoutId = 0; if (attrs != null) { TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.VideoPlayerView, 0, 0); try { icBackImage = a.getResourceId(R.styleable.VideoPlayerView_player_back_image, icBackImage); userWatermark = a.getResourceId(R.styleable.VideoPlayerView_user_watermark, 0); isListPlayer = a.getBoolean(R.styleable.VideoPlayerView_player_list, false); replayId = a.getResourceId(R.styleable.VideoPlayerView_player_replay_layout_id, replayId); errorId = a.getResourceId(R.styleable.VideoPlayerView_player_error_layout_id, errorId); playerHintId = a.getResourceId(R.styleable.VideoPlayerView_player_hint_layout_id, playerHintId); defaultArtworkId = a.getResourceId(R.styleable.VideoPlayerView_default_artwork, defaultArtworkId); loadId = a.getResourceId(R.styleable.VideoPlayerView_player_load_layout_id, loadId); audioId = a.getResourceId(R.styleable.VideoPlayerView_player_gesture_audio_layout_id, audioId); videoProgressId = a.getResourceId(R.styleable.VideoPlayerView_player_gesture_progress_layout_id, videoProgressId); brightnessId = a.getResourceId(R.styleable.VideoPlayerView_player_gesture_bright_layout_id, brightnessId); preViewLayoutId = a.getResourceId(R.styleable.VideoPlayerView_player_preview_layout_id, preViewLayoutId); } finally { a.recycle(); } } exoPlayErrorLayout = inflate(context, errorId, null); playReplayLayout = inflate(context, replayId, null); playBtnHintLayout = inflate(context, playerHintId, null); exoLoadingLayout = inflate(context, loadId, null); exoAudioLayout = inflate(context, audioId, null); exoBrightnessLayout = inflate(context, brightnessId, null); dialogProLayout = inflate(context, videoProgressId, null); exoPlayLockLayout = inflate(context, R.layout.simple_exo_play_lock, null); if (preViewLayoutId != 0) { exoPlayPreviewLayout = inflate(context, preViewLayoutId, null); } intiView(); intiGestureView(audioId, brightnessId, videoProgressId); initWatermark(userWatermark, defaultArtworkId); }
@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); } }
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); } } } }); }
VideoPlayerComponent(Context context, SimpleExoPlayerView simpleExoPlayerView, String videoUrl) { this.context = context; this.simpleExoPlayerView = simpleExoPlayerView; this.videoUrl = videoUrl; }
public void setView(SimpleExoPlayerView videoView) { videoView.setPlayer(player); }
private void initViews() { simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.player_view); textureView = (TextureView) simpleExoPlayerView.getVideoSurfaceView(); }
@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); } }
/*** * 获取内核播放view * * @return SimpleExoPlayerView player view */ @NonNull public SimpleExoPlayerView getPlayerView() { return playerView; }