@Override public void startPlayer() { if(exoPlayer==null){ exoPlayer = ExoPlayerFactory.newSimpleInstance( context, new DefaultTrackSelector(), new DefaultLoadControl()); exoPlayer.addListener(this); } exoPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory( context, Util.getUserAgent(context, "uamp"), null); ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); MediaSource mediaSource = new ExtractorMediaSource( Uri.parse(currentUrl), dataSourceFactory, extractorsFactory, null, null); exoPlayer.prepare(mediaSource); configPlayer(); }
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 initializePlayer() { if (player == null) { trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(context, trackSelector); player.addListener(this); DefaultDataSourceFactory dataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context, "testApp"), bandwidthMeter); ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); ExtractorMediaSource videoSource = new ExtractorMediaSource(Uri.parse(videoUrl), dataSourceFactory, extractorsFactory, null, null); simpleExoPlayerView.setPlayer(player); player.setPlayWhenReady(true); boolean haveResumePosition = resumeWindow != C.INDEX_UNSET; if (haveResumePosition) { Log.d(TAG, "Have Resume position true!" + resumePosition); player.seekTo(resumeWindow, resumePosition); } player.prepare(videoSource, !haveResumePosition, false); } }
@Override protected MediaSource[] doInBackground(MediaFile... media) { try { browser = Browser.getInstance(Config.mountDirectory); DataSource.Factory dataSourceFactory = new NfsDataSourceFactory(browser.getContext()); ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); MediaSource videoSource = new ExtractorMediaSource(Uri.parse("nfs://host/" + media[0].getPath()), dataSourceFactory, extractorsFactory, null, null); if (media[0].getSubtitlePath() != null) { Format subtitleFormat = Format.createTextSampleFormat(null, MimeTypes.APPLICATION_SUBRIP, null, Format.NO_VALUE, Format.NO_VALUE, "en", null); MediaSource subtitleSource = new SingleSampleMediaSource(Uri.parse("nfs://host/" + media[0].getSubtitlePath()), dataSourceFactory, subtitleFormat, Long.MAX_VALUE, 0); return new MediaSource[]{videoSource, subtitleSource}; } else return new MediaSource[]{videoSource}; } catch (IOException e) { e.printStackTrace(); } return null; }
private void prepare(boolean playWhenReady, boolean resetPosition) { mInvalid = false; if (mQueue == null) { return; } DataSource.Factory srcFactory = new DefaultDataSourceFactory(mContext, USER_AGENT); ExtractorsFactory extFactory = new DefaultExtractorsFactory(); int startingPosition = resetPosition ? 0 : getCurrentPosition(); if (mRepeatOne) { mExoPlayer.prepare(buildRepeatOneMediaSource(srcFactory, extFactory)); } else if (mRepeatAll) { mExoPlayer.prepare(buildRepeatAllMediaSource(srcFactory, extFactory)); } else { mExoPlayer.prepare(buildNoRepeatMediaSource(srcFactory, extFactory)); } mExoPlayer.seekTo(mQueueIndex, startingPosition); mExoPlayer.setPlayWhenReady(playWhenReady); }
/** * @param uri The {@link Uri} of the media stream. * @param dataSourceFactory A factory for {@link DataSource}s to read the media. * @param extractorsFactory A factory for {@link Extractor}s to process the media stream. If the * possible formats are known, pass a factory that instantiates extractors for those formats. * Otherwise, pass a {@link DefaultExtractorsFactory} to use default extractors. * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs. * @param eventHandler A handler for events. May be null if delivery of events is not required. * @param eventListener A listener of events. May be null if delivery of events is not required. * @param customCacheKey A custom key that uniquely identifies the original stream. Used for cache * indexing. May be null. * @param continueLoadingCheckIntervalBytes The number of bytes that should be loaded between each * invocation of {@link MediaPeriod.Callback#onContinueLoadingRequested(SequenceableLoader)}. * @deprecated Use {@link Factory} instead. */ @Deprecated public ExtractorMediaSource( Uri uri, DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory, int minLoadableRetryCount, Handler eventHandler, EventListener eventListener, String customCacheKey, int continueLoadingCheckIntervalBytes) { this( uri, dataSourceFactory, extractorsFactory, minLoadableRetryCount, eventHandler, eventListener == null ? null : new EventListenerWrapper(eventListener), customCacheKey, continueLoadingCheckIntervalBytes); }
private ExtractorMediaSource( Uri uri, DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory, int minLoadableRetryCount, @Nullable Handler eventHandler, @Nullable MediaSourceEventListener eventListener, @Nullable String customCacheKey, int continueLoadingCheckIntervalBytes) { this.uri = uri; this.dataSourceFactory = dataSourceFactory; this.extractorsFactory = extractorsFactory; this.minLoadableRetryCount = minLoadableRetryCount; this.eventDispatcher = new EventDispatcher(eventHandler, eventListener); this.customCacheKey = customCacheKey; this.continueLoadingCheckIntervalBytes = continueLoadingCheckIntervalBytes; }
/** * 播放启动视频 */ 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 void setupMediaPlayer() { DataSource.Factory dsf = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "R/a/dio-Android-App")); ExtractorsFactory extractors = new DefaultExtractorsFactory(); MediaSource audioSource = new ExtractorMediaSource(Uri.parse(radio_url), dsf, extractors, null, null); if(sep != null) sep.prepare(audioSource); }
private MediaSource getMediaSource(String videoUrl) { DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); // Produces DataSource instances through which media data is loaded. // DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getContext(), Util.getUserAgent(getContext(), "Loop"), bandwidthMeter); DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(MAVApplication.getInstance().getApplicationContext(), Util.getUserAgent(MAVApplication.getInstance().getApplicationContext(), "Loop"), bandwidthMeter); // Produces Extractor instances for parsing the media data. ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); // This is the MediaSource representing the media to be played. MediaSource mediaSource = new ExtractorMediaSource(Uri.parse(videoUrl), dataSourceFactory, extractorsFactory, null, null); // Loops the video indefinitely. // LoopingMediaSource loopingSource = new LoopingMediaSource(mediaSource); return mediaSource; }
private MediaSource getMediaSource(String videoUrl) { DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); // Produces DataSource instances through which media data is loaded. // DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "Loop"), bandwidthMeter); DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(MAVApplication.getInstance().getApplicationContext(), Util.getUserAgent(MAVApplication.getInstance().getApplicationContext(), "Loop"), bandwidthMeter); // Produces Extractor instances for parsing the media data. ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); // This is the MediaSource representing the media to be played. MediaSource mediaSource = new ExtractorMediaSource(Uri.parse(videoUrl), dataSourceFactory, extractorsFactory, null, null); // Loops the video indefinitely. // LoopingMediaSource loopingSource = new LoopingMediaSource(mediaSource); return mediaSource; }
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); }
/** * @param uri The {@link Uri} of the media stream. * @param dataSourceFactory A factory for {@link DataSource}s to read the media. * @param extractorsFactory A factory for {@link Extractor}s to process the media stream. If the * possible formats are known, pass a factory that instantiates extractors for those formats. * Otherwise, pass a {@link DefaultExtractorsFactory} to use default extractors. * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs. * @param eventHandler A handler for events. May be null if delivery of events is not required. * @param eventListener A listener of events. May be null if delivery of events is not required. * @param customCacheKey A custom key that uniquely identifies the original stream. Used for cache * indexing. May be null. */ public ExtractorMediaSource(Uri uri, DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory, int minLoadableRetryCount, Handler eventHandler, EventListener eventListener, String customCacheKey) { this.uri = uri; this.dataSourceFactory = dataSourceFactory; this.extractorsFactory = extractorsFactory; this.minLoadableRetryCount = minLoadableRetryCount; this.eventHandler = eventHandler; this.eventListener = eventListener; this.customCacheKey = customCacheKey; period = new Timeline.Period(); }
public void play(){ if (song != null) { try { if (pausePos != null) { player.seekTo(pausePos); } else { DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getApplicationContext(), Util.getUserAgent(getApplicationContext(), "BeatPulse")); // Produces Extractor instances for parsing the media data. ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); // This is the MediaSource representing the media to be played. MediaSource songSource = new ExtractorMediaSource(song.getFileUri(), dataSourceFactory, extractorsFactory, null, null); player.prepare(songSource); } player.setPlayWhenReady(true); } catch (Exception exc) { //Catches the exception raised when preparing the same FFmpegMediaPlayer multiple times. Log.d(TAG, "Exception occurred while starting to play " + song.getName(), exc); } Realm realm = Realm.getDefaultInstance(); realm.beginTransaction(); realm.copyToRealmOrUpdate(song); realm.commitTransaction(); if (showNotification) { showNotification(); } Intent broadcastIntent = new Intent(); broadcastIntent.setAction("MEDIA_PLAYER_STARTED"); LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(broadcastIntent); } }
/** * @param uri The {@link Uri} of the media stream. * @param dataSourceFactory A factory for {@link DataSource}s to read the media. * @param extractorsFactory A factory for {@link Extractor}s to process the media stream. If the * possible formats are known, pass a factory that instantiates extractors for those formats. * Otherwise, pass a {@link DefaultExtractorsFactory} to use default extractors. * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs. * @param eventHandler A handler for events. May be null if delivery of events is not required. * @param eventListener A listener of events. May be null if delivery of events is not required. */ public ExtractorMediaSource(Uri uri, DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory, int minLoadableRetryCount, Handler eventHandler, EventListener eventListener) { this.uri = uri; this.dataSourceFactory = dataSourceFactory; this.extractorsFactory = extractorsFactory; this.minLoadableRetryCount = minLoadableRetryCount; this.eventHandler = eventHandler; this.eventListener = eventListener; period = new Timeline.Period(); }
@Provides static MediaSourceFactory provideMediaSourceFactory(final DataSource.Factory dataSourceFactory, final ExtractorsFactory extractorsFactory) { return uri -> new ExtractorMediaSource(Uri.parse(uri), dataSourceFactory, extractorsFactory, null, null); }
private MediaSource getMediaSource(String videoUrl){ DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); // Produces DataSource instances through which media data is loaded. // DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getContext(), Util.getUserAgent(getContext(), "Loop"), bandwidthMeter); DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(LoopApplication.getInstance().getApplicationContext(), Util.getUserAgent(LoopApplication.getInstance().getApplicationContext(), "Loop"), bandwidthMeter); // Produces Extractor instances for parsing the media data. ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); // This is the MediaSource representing the media to be played. MediaSource mediaSource = new ExtractorMediaSource(Uri.parse(videoUrl), dataSourceFactory, extractorsFactory, null, null); // Loops the video indefinitely. // LoopingMediaSource loopingSource = new LoopingMediaSource(mediaSource); return mediaSource; }
private MediaSource buildRepeatOneMediaSource(DataSource.Factory srcFactory, ExtractorsFactory extFactory) { if (mQueue.isEmpty()) { // We need to return an empty MediaSource (can't be null), so return a // ConcatenatingMediaSource with nothing to concatenate return new ConcatenatingMediaSource(); } Uri uri = mQueue.get(mQueueIndex).getLocation(); MediaSource source = new ExtractorMediaSource(uri, srcFactory, extFactory, null, null); return new LoopingMediaSource(source); }
private MediaSource buildNoRepeatMediaSource(DataSource.Factory srcFactory, ExtractorsFactory extFactory) { MediaSource[] queue = new MediaSource[mQueue.size()]; for (int i = 0; i < queue.length; i++) { Uri uri = mQueue.get(i).getLocation(); queue[i] = new ExtractorMediaSource(uri, srcFactory, extFactory, null, null); } return new ConcatenatingMediaSource(queue); }
@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); } }
@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(); } } }); }
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); }
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(); } }); }
public ExtractorsFactory getExtractorsFactory() { return extractorsFactory; }
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); } } } }); }
@Override protected String doInBackground(String... params) { try{ String text=URLEncoder.encode(simplify(params[0]), "UTF-8"); String url=String.format(API, text); // final MediaPlayer mpeg=new MediaPlayer(); //mpeg.setDataSource(); //getMainLooper().prepare(); // Handler mainHandler = new Handler(); // Produces DataSource instances through which media data is loaded. DefaultBandwidthMeter bandwidthMeter2 = new DefaultBandwidthMeter(); DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(ActKana.this, Util.getUserAgent(ActKana.this, "SimpleGojuuon"), bandwidthMeter2); // Produces Extractor instances for parsing the media data. ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); // This is the MediaSource representing the media to be played. System.out.println("extract audio url:"+followRedirects(new URL(url))); MediaSource videoSource = new ExtractorMediaSource(Uri.parse(followRedirects(new URL(url))), dataSourceFactory, extractorsFactory, null, null); // Prepare the player with the source. player.prepare(videoSource); player.setPlayWhenReady(true); // EMAudioPlayer player = new EMAudioPlayer(ActKana.this); // // player.setDataSource(ActKana.this, Uri.parse()); // player.prepareAsync(); // player.start(); // MediaPlayer.create() // // mpeg.setDataSource(ActKana.this, Uri.parse(followRedirects(new URL(url)))); // mpeg.prepareAsync(); // mpeg.start(); // mpeg.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {//完毕事件 // @Override // public void onCompletion(MediaPlayer arg0) { // mpeg.release(); // } // }); } catch(Exception e){ e.printStackTrace(); isNoError=false; } return params[0]; }
@Provides static ExtractorsFactory provideExtractorsFactory() { return new DefaultExtractorsFactory(); }
@Override public void play(QueueItem item) { mPlayOnFocusGain = true; tryToGetAudioFocus(); registerAudioNoisyReceiver(); String mediaId = item.getDescription().getMediaId(); boolean mediaHasChanged = !TextUtils.equals(mediaId, mCurrentMediaId); if (mediaHasChanged) { mCurrentMediaId = mediaId; } if (mediaHasChanged || mExoPlayer == null) { releaseResources(false); // release everything except the player MediaMetadataCompat track = mMusicProvider.getMusic( MediaIDHelper.extractMusicIDFromMediaID( item.getDescription().getMediaId())); String source = track.getString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE); if (source != null) { source = source.replaceAll(" ", "%20"); // Escape spaces for URLs } if (mExoPlayer == null) { mExoPlayer = ExoPlayerFactory.newSimpleInstance( mContext, new DefaultTrackSelector(), new DefaultLoadControl()); mExoPlayer.addListener(mEventListener); } // Android "O" makes much greater use of AudioAttributes, especially // with regards to AudioFocus. All of UAMP's tracks are music, but // if your content includes spoken word such as audiobooks or podcasts // then the content type should be set to CONTENT_TYPE_SPEECH for those // tracks. final AudioAttributes audioAttributes = new AudioAttributes.Builder() .setContentType(CONTENT_TYPE_MUSIC) .setUsage(USAGE_MEDIA) .build(); mExoPlayer.setAudioAttributes(audioAttributes); // Produces DataSource instances through which media data is loaded. DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory( mContext, Util.getUserAgent(mContext, "uamp"), null); // Produces Extractor instances for parsing the media data. ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); // The MediaSource represents the media to be played. MediaSource mediaSource = new ExtractorMediaSource( Uri.parse(source), dataSourceFactory, extractorsFactory, null, null); // Prepares media to play (happens on background thread) and triggers // {@code onPlayerStateChanged} callback when the stream is ready to play. mExoPlayer.prepare(mediaSource); // If we are streaming from the internet, we want to hold a // Wifi lock, which prevents the Wifi radio from going to // sleep while the song is playing. mWifiLock.acquire(); } configurePlayerState(); }
private MediaSource buildRepeatAllMediaSource(DataSource.Factory sourceFactory, ExtractorsFactory extractorsFactory) { MediaSource queue = buildNoRepeatMediaSource(sourceFactory, extractorsFactory); return new LoopingMediaSource(queue); }
/** * @param uri The {@link Uri} of the media stream. * @param dataSourceFactory A factory for {@link DataSource}s to read the media. * @param extractorsFactory A factory for {@link Extractor}s to process the media stream. If the * possible formats are known, pass a factory that instantiates extractors for those formats. * Otherwise, pass a {@link DefaultExtractorsFactory} to use default extractors. * @param eventHandler A handler for events. May be null if delivery of events is not required. * @param eventListener A listener of events. May be null if delivery of events is not required. * @param customCacheKey A custom key that uniquely identifies the original stream. Used for cache * indexing. May be null. */ public ExtractorMediaSource(Uri uri, DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory, Handler eventHandler, EventListener eventListener, String customCacheKey) { this(uri, dataSourceFactory, extractorsFactory, MIN_RETRY_COUNT_DEFAULT_FOR_MEDIA, eventHandler, eventListener, customCacheKey); }
/** * @param uri The {@link Uri} of the media stream. * @param dataSourceFactory A factory for {@link DataSource}s to read the media. * @param extractorsFactory A factory for {@link Extractor}s to process the media stream. If the * possible formats are known, pass a factory that instantiates extractors for those formats. * Otherwise, pass a {@link DefaultExtractorsFactory} to use default extractors. * @param eventHandler A handler for events. May be null if delivery of events is not required. * @param eventListener A listener of events. May be null if delivery of events is not required. * @deprecated Use {@link Factory} instead. */ @Deprecated public ExtractorMediaSource( Uri uri, DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory, Handler eventHandler, EventListener eventListener) { this(uri, dataSourceFactory, extractorsFactory, eventHandler, eventListener, null); }
/** * @param uri The {@link Uri} of the media stream. * @param dataSourceFactory A factory for {@link DataSource}s to read the media. * @param extractorsFactory A factory for {@link Extractor}s to process the media stream. If the * possible formats are known, pass a factory that instantiates extractors for those formats. * Otherwise, pass a {@link DefaultExtractorsFactory} to use default extractors. * @param eventHandler A handler for events. May be null if delivery of events is not required. * @param eventListener A listener of events. May be null if delivery of events is not required. * @param customCacheKey A custom key that uniquely identifies the original stream. Used for cache * indexing. May be null. * @deprecated Use {@link Factory} instead. */ @Deprecated public ExtractorMediaSource( Uri uri, DataSource.Factory dataSourceFactory, ExtractorsFactory extractorsFactory, Handler eventHandler, EventListener eventListener, String customCacheKey) { this(uri, dataSourceFactory, extractorsFactory, MIN_RETRY_COUNT_DEFAULT_FOR_MEDIA, eventHandler, eventListener, customCacheKey, DEFAULT_LOADING_CHECK_INTERVAL_BYTES); }