Java Code Examples for com.google.android.exoplayer2.util.Util#getUserAgent()
The following examples show how to use
com.google.android.exoplayer2.util.Util#getUserAgent() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VideoActivity.java From arcusandroid with Apache License 2.0 | 7 votes |
private void initializePlayer() { CameraPreviewGetter.instance().pauseUpdates(); PlayerView video = findViewById(R.id.video_view); video.setUseController(playbackModel.getType() == PlaybackModel.PlaybackType.CLIP); video.requestFocus(); TrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory(DEFAULT_BANDWIDTH_METER); player = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(this), new DefaultTrackSelector(trackSelectionFactory), new DefaultLoadControl() ); video.setPlayer(player); String userAgent = Util.getUserAgent(this, getPackageName()); DataSource.Factory dsf = new DefaultDataSourceFactory(this, userAgent); MediaSource mediaSource = new HlsMediaSource.Factory(dsf).createMediaSource(Uri.parse(playbackModel.getUrl())); player.prepare(mediaSource); player.addListener(eventListener); player.setPlayWhenReady(playWhenReady); player.seekTo(currentWindow, playbackPosition); }
Example 2
Source File: ExoPlayerHelper.java From ExoPlayer-Wrapper with Apache License 2.0 | 6 votes |
private void init() { // Measures bandwidth during playback. Can be null if not required. DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter.Builder(mContext).build(); // Produces DataSource instances through which media data is loaded. mDataSourceFactory = new DefaultDataSourceFactory(mContext, Util.getUserAgent(mContext, mContext.getString(R.string.app_name)), bandwidthMeter); // LoadControl that controls when the MediaSource buffers more media, and how much media is buffered. // LoadControl is injected when the player is created. //removed deprecated DefaultLoadControl creation method DefaultLoadControl.Builder builder = new DefaultLoadControl.Builder(); builder.setAllocator(new DefaultAllocator(true, 2 * 1024 * 1024)); builder.setBufferDurationsMs(5000, 5000, 5000, 5000); builder.setPrioritizeTimeOverSizeThresholds(true); mLoadControl = builder.createDefaultLoadControl(); }
Example 3
Source File: MediaPlayback21.java From Melophile with Apache License 2.0 | 6 votes |
@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(); }
Example 4
Source File: PlaybackFragment.java From androidtv-Leanback with Apache License 2.0 | 5 votes |
private void prepareMediaForPlaying(Uri mediaSourceUri) { String userAgent = Util.getUserAgent(getActivity(), "VideoPlayerGlue"); MediaSource mediaSource = new ExtractorMediaSource( mediaSourceUri, new DefaultDataSourceFactory(getActivity(), userAgent), new DefaultExtractorsFactory(), null, null); mPlayer.prepare(mediaSource); }
Example 5
Source File: DemoApplication.java From TubiPlayer with MIT License | 5 votes |
@Override public void onCreate() { super.onCreate(); initFabric(this); userAgent = Util.getUserAgent(this, "ExoPlayerDemo"); }
Example 6
Source File: VideoViewActivity.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 5 votes |
@Override protected void onStart() { super.onStart(); // Create a new Exo Player player = ExoPlayerFactory.newSimpleInstance(this, new DefaultTrackSelector()); // Associate the ExoPlayer with the Player View playerView.setPlayer(player); // Build a DataSource.Factory capable of // loading http and local content DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory( this, Util.getUserAgent(this, getString(R.string.app_name))); // Specify the URI to play File file = new File(Environment.getExternalStorageDirectory(), // TODO Replace with a real file. "test2.mp4"); ExtractorMediaSource mediaSource = new ExtractorMediaSource.Factory(dataSourceFactory) .createMediaSource(Uri.fromFile(file)); // Start loading the media source player.prepare(mediaSource); // Start playback automatically when ready player.setPlayWhenReady(true); }
Example 7
Source File: ExoMediaPlayer.java From PainlessMusicPlayer with Apache License 2.0 | 5 votes |
@Override public void init(@NonNull final Context context) { final TrackSelector trackSelector = new DefaultTrackSelector(); exoPlayer = ExoPlayerFactory.newSimpleInstance( new DefaultRenderersFactory(context), trackSelector, new DefaultLoadControl()); exoPlayer.addListener(mEventListener); exoPlayer.addAudioDebugListener(mAudioRendererEventListener); dataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context, "Painless Music Player")); }
Example 8
Source File: ExoPlayerAdapter.java From leanback-showcase with Apache License 2.0 | 5 votes |
/** * Set {@link MediaSource} for {@link SimpleExoPlayer}. An app may override this method in order * to use different {@link MediaSource}. * @param uri The url of media source * @return MediaSource for the player */ public MediaSource onCreateMediaSource(Uri uri) { String userAgent = Util.getUserAgent(mContext, "ExoPlayerAdapter"); return new ExtractorMediaSource(uri, new DefaultDataSourceFactory(mContext, userAgent), new DefaultExtractorsFactory(), null, null); }
Example 9
Source File: MediaVideoView.java From Slide with GNU General Public License v3.0 | 5 votes |
CacheDataSourceFactory(Context context, long maxCacheSize, long maxFileSize) { super(); this.context = context; this.maxCacheSize = maxCacheSize; this.maxFileSize = maxFileSize; String userAgent = Util.getUserAgent(context, context.getString(R.string.app_name)); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); defaultDatasourceFactory = new DefaultDataSourceFactory(this.context, bandwidthMeter, new DefaultHttpDataSourceFactory(userAgent, bandwidthMeter)); }
Example 10
Source File: LocalPlayback.java From klingar with Apache License 2.0 | 5 votes |
LocalPlayback(Context context, MusicController musicController, AudioManager audioManager, WifiManager wifiManager, Call.Factory callFactory) { this.context = context; this.musicController = musicController; this.audioManager = audioManager; this.wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "klingar"); String agent = Util.getUserAgent(context, context.getResources().getString(R.string.app_name)); this.mediaSourceFactory = new ProgressiveMediaSource.Factory(new DefaultDataSourceFactory( context, null, new OkHttpDataSourceFactory(callFactory, agent))); }
Example 11
Source File: VideoPlayer.java From edx-app-android with Apache License 2.0 | 5 votes |
/** * Function that provides the media source played by ExoPlayer based on media type. * * @param videoUrl Video URL * @return The {@link MediaSource} to play. */ private MediaSource getMediaSource(String videoUrl) { final String userAgent = Util.getUserAgent(this.context, this.context.getString(R.string.app_name)); final DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this.context, userAgent); final MediaSource mediaSource; if (VideoUtil.videoHasFormat(videoUrl, VIDEO_FORMAT_M3U8)) { mediaSource = new HlsMediaSource.Factory(dataSourceFactory) .createMediaSource(Uri.parse(videoUrl)); } else { mediaSource = new ExtractorMediaSource.Factory(dataSourceFactory) .createMediaSource(Uri.parse(videoUrl)); } return mediaSource; }
Example 12
Source File: PlayerService.java From AndroidAudioExample with MIT License | 4 votes |
@Override public void onCreate() { super.onCreate(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { @SuppressLint("WrongConstant") NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_DEFAULT_CHANNEL_ID, getString(R.string.notification_channel_name), NotificationManagerCompat.IMPORTANCE_DEFAULT); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.createNotificationChannel(notificationChannel); AudioAttributes audioAttributes = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_MEDIA) .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) .build(); audioFocusRequest = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN) .setOnAudioFocusChangeListener(audioFocusChangeListener) .setAcceptsDelayedFocusGain(false) .setWillPauseWhenDucked(true) .setAudioAttributes(audioAttributes) .build(); } audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mediaSession = new MediaSessionCompat(this, "PlayerService"); mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); mediaSession.setCallback(mediaSessionCallback); Context appContext = getApplicationContext(); Intent activityIntent = new Intent(appContext, MainActivity.class); mediaSession.setSessionActivity(PendingIntent.getActivity(appContext, 0, activityIntent, 0)); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null, appContext, MediaButtonReceiver.class); mediaSession.setMediaButtonReceiver(PendingIntent.getBroadcast(appContext, 0, mediaButtonIntent, 0)); exoPlayer = ExoPlayerFactory.newSimpleInstance(this, new DefaultRenderersFactory(this), new DefaultTrackSelector(), new DefaultLoadControl()); exoPlayer.addListener(exoPlayerListener); DataSource.Factory httpDataSourceFactory = new OkHttpDataSourceFactory(new OkHttpClient(), Util.getUserAgent(this, getString(R.string.app_name))); Cache cache = new SimpleCache(new File(this.getCacheDir().getAbsolutePath() + "/exoplayer"), new LeastRecentlyUsedCacheEvictor(1024 * 1024 * 100)); // 100 Mb max this.dataSourceFactory = new CacheDataSourceFactory(cache, httpDataSourceFactory, CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR); this.extractorsFactory = new DefaultExtractorsFactory(); }
Example 13
Source File: MainActivity.java From WhatsAppStatusSaver with Apache License 2.0 | 4 votes |
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).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(); } }); }
Example 14
Source File: MusicService.java From YTPlayer with GNU General Public License v3.0 | 4 votes |
public static void functionInMainActivity(Context activity) { // Toast.makeText(activity, "Function in MainActivity...!", Toast.LENGTH_SHORT).show(); MusicService.activity = activity.getApplicationContext(); settingPref = activity.getSharedPreferences("settings",MODE_PRIVATE); isEqualizerEnabled = settingPref.getBoolean("equalizer_enabled",false); dataSourceFactory = new DefaultDataSourceFactory(activity, Util.getUserAgent(activity, activity.getResources().getString(R.string.app_name)), BANDWIDTH_METER); player = ExoPlayerFactory.newSimpleInstance(activity, trackSelector); createNotification(activity); playListItems = new ArrayList<>(); yturls = new ArrayList<>(); nPlayModels = new ArrayList<>(); ComponentName mediaButtonReceiverComponentName = new ComponentName( activity, SongBroadCast.class); Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(mediaButtonReceiverComponentName); PendingIntent mediaButtonReceiverPendingIntent = PendingIntent.getBroadcast( activity, 0, mediaButtonIntent, 0); mediaSession = new MediaSessionCompat(activity, "MusicPlayer", mediaButtonReceiverComponentName, mediaButtonReceiverPendingIntent); mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS ); mediaSession.setCallback(mMediaSessionCallback); mediaSession.setActive(true); mediaSession.setMediaButtonReceiver(mediaButtonReceiverPendingIntent); preferences = activity.getSharedPreferences("history",MODE_PRIVATE); }
Example 15
Source File: ExoPlayerMediaSourceBuilder.java From PreviewSeekBar with Apache License 2.0 | 4 votes |
private DataSource.Factory getHttpDataSourceFactory(boolean preview) { return new DefaultHttpDataSourceFactory(Util.getUserAgent(context, "ExoPlayerDemo"), preview ? null : bandwidthMeter); }
Example 16
Source File: PlayerActivity.java From leafpicrevived with GNU General Public License v3.0 | 4 votes |
private HttpDataSource.Factory buildHttpDataSourceFactory(boolean useBandwidthMeter) { return new DefaultHttpDataSourceFactory(Util.getUserAgent(this, "LeafPic"), useBandwidthMeter ? BANDWIDTH_METER : null); }
Example 17
Source File: ExoMediaSourceHelper.java From DKVideoPlayer with Apache License 2.0 | 4 votes |
private ExoMediaSourceHelper(Context context) { mAppContext = context.getApplicationContext(); mUserAgent = Util.getUserAgent(mAppContext, mAppContext.getApplicationInfo().name); }
Example 18
Source File: MediaHelper.java From TubiPlayer with MIT License | 4 votes |
public static @NonNull HttpDataSource.Factory buildHttpDataSourceFactory(@NonNull Context context, @NonNull DefaultBandwidthMeter bandwidthMeter) { return new DefaultHttpDataSourceFactory(Util.getUserAgent(context, "TubiExoPlayer"), bandwidthMeter); }
Example 19
Source File: ExoPlayerImpl.java From MediaSDK with Apache License 2.0 | 4 votes |
private DataSource.Factory buildDataSourceFactory() { String userAgent = Util.getUserAgent(mContext, "ExoPlayerDemo"); DefaultDataSourceFactory upstreamFactory = new DefaultDataSourceFactory(mContext, new DefaultHttpDataSourceFactory(userAgent)); return upstreamFactory; }