use of com.google.android.exoplayer2.DefaultRenderersFactory in project PainlessMusicPlayer by Doctoror.
the class ExoMediaPlayer method init.
@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, "Fuck Off Music Player"));
}
use of com.google.android.exoplayer2.DefaultRenderersFactory in project AndroidAudioExample by SergeyVinyar.
the class PlayerService method onCreate.
@Override
public void onCreate() {
super.onCreate();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
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(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)), null);
// 100 Mb max
Cache cache = new SimpleCache(new File(this.getCacheDir().getAbsolutePath() + "/exoplayer"), new LeastRecentlyUsedCacheEvictor(1024 * 1024 * 100));
this.dataSourceFactory = new CacheDataSourceFactory(cache, httpDataSourceFactory, CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR);
this.extractorsFactory = new DefaultExtractorsFactory();
}
use of com.google.android.exoplayer2.DefaultRenderersFactory in project NewPipe by TeamNewPipe.
the class BasePlayer method initPlayer.
public void initPlayer() {
if (DEBUG)
Log.d(TAG, "initPlayer() called with: context = [" + context + "]");
if (databaseUpdateReactor != null)
databaseUpdateReactor.dispose();
databaseUpdateReactor = new CompositeDisposable();
final String userAgent = Downloader.USER_AGENT;
final DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
dataSource = new PlayerDataSource(context, userAgent, bandwidthMeter);
final AdaptiveTrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
trackSelector = new CustomTrackSelector(trackSelectionFactory);
final LoadControl loadControl = new LoadController(context);
final RenderersFactory renderFactory = new DefaultRenderersFactory(context);
simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(renderFactory, trackSelector, loadControl);
simpleExoPlayer.addListener(this);
simpleExoPlayer.setPlayWhenReady(true);
simpleExoPlayer.setSeekParameters(PlayerHelper.getSeekParameters(context));
audioReactor = new AudioReactor(context, simpleExoPlayer);
mediaSessionManager = new MediaSessionManager(context, simpleExoPlayer, new BasePlayerMediaSession(this));
}
use of com.google.android.exoplayer2.DefaultRenderersFactory in project ExoPlayer by google.
the class DefaultRenderersFactoryAsserts method assertExtensionRendererCreated.
/**
* Asserts that an extension renderer of type {@code clazz} is not instantiated for {@link
* DefaultRenderersFactory#EXTENSION_RENDERER_MODE_OFF}, and that it's instantiated in the correct
* position relative to other renderers of the same type for {@link
* DefaultRenderersFactory#EXTENSION_RENDERER_MODE_ON} and {@link
* DefaultRenderersFactory#EXTENSION_RENDERER_MODE_PREFER}, assuming no other extension renderers
* can be loaded.
*
* @param clazz The extension renderer class.
* @param type The type of the renderer.
*/
public static void assertExtensionRendererCreated(Class<? extends Renderer> clazz, @C.TrackType int type) {
// In EXTENSION_RENDERER_MODE_OFF the renderer should not be created.
Renderer[] renderers = createRenderers(EXTENSION_RENDERER_MODE_OFF);
for (Renderer renderer : renderers) {
assertThat(renderer).isNotInstanceOf(clazz);
}
// In EXTENSION_RENDERER_MODE_ON the renderer should be created and last of its type.
renderers = createRenderers(EXTENSION_RENDERER_MODE_ON);
boolean found = false;
for (Renderer renderer : renderers) {
if (!found) {
if (clazz.isInstance(renderer)) {
found = true;
}
} else {
assertThat(renderer.getTrackType()).isNotEqualTo(type);
}
}
assertThat(found).isTrue();
// In EXTENSION_RENDERER_MODE_PREFER the renderer should be created and first of its type.
renderers = createRenderers(EXTENSION_RENDERER_MODE_PREFER);
found = false;
for (Renderer renderer : renderers) {
if (!found) {
if (clazz.isInstance(renderer)) {
found = true;
} else {
assertThat(renderer.getTrackType()).isNotEqualTo(type);
}
} else {
assertThat(renderer).isNotInstanceOf(clazz);
}
}
assertThat(found).isTrue();
}
use of com.google.android.exoplayer2.DefaultRenderersFactory in project LeafPic by HoraApps.
the class PlayerActivity method initializePlayer.
// Internal methods
private void initializePlayer() {
Intent intent = getIntent();
boolean needNewPlayer = player == null;
if (needNewPlayer) {
TrackSelection.Factory adaptiveTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
trackSelector = new DefaultTrackSelector(adaptiveTrackSelectionFactory);
trackSelectionHelper = new TrackSelectionHelper(trackSelector, adaptiveTrackSelectionFactory, getThemeHelper());
lastSeenTrackGroupArray = null;
UUID drmSchemeUuid = intent.hasExtra(DRM_SCHEME_UUID_EXTRA) ? UUID.fromString(intent.getStringExtra(DRM_SCHEME_UUID_EXTRA)) : null;
DrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null;
if (drmSchemeUuid != null) {
String drmLicenseUrl = intent.getStringExtra(DRM_LICENSE_URL);
String[] keyRequestPropertiesArray = intent.getStringArrayExtra(DRM_KEY_REQUEST_PROPERTIES);
boolean multiSession = intent.getBooleanExtra(DRM_MULTI_SESSION, false);
int errorStringId = R.string.error_drm_unknown;
try {
drmSessionManager = buildDrmSessionManagerV18(drmSchemeUuid, drmLicenseUrl, keyRequestPropertiesArray, multiSession);
} catch (UnsupportedDrmException e) {
errorStringId = e.reason == UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME ? R.string.error_drm_unsupported_scheme : R.string.error_drm_unknown;
}
if (drmSessionManager == null) {
showToast(errorStringId);
return;
}
}
DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this, drmSessionManager, DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER);
player = ExoPlayerFactory.newSimpleInstance(renderersFactory, trackSelector);
player.addListener(new PlayerEventListener());
simpleExoPlayerView.setPlayer(player);
player.setPlayWhenReady(shouldAutoPlay);
}
String action = intent.getAction();
Uri[] uris;
String[] extensions;
if (intent.getData() != null && intent.getType() != null) {
uris = new Uri[] { intent.getData() };
extensions = new String[] { intent.getType() };
} else {
// TODO: 12/7/16 asdasd
showToast(getString(R.string.unexpected_intent_action, action));
return;
}
MediaSource[] mediaSources = new MediaSource[uris.length];
for (int i = 0; i < uris.length; i++) {
mediaSources[i] = buildMediaSource(uris[i], extensions[i]);
}
MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0] : new ConcatenatingMediaSource(mediaSources);
boolean haveResumePosition = resumeWindow != C.INDEX_UNSET;
if (haveResumePosition) {
player.seekTo(resumeWindow, resumePosition);
}
player.prepare(mediaSource, !haveResumePosition, false);
inErrorState = false;
supportInvalidateOptionsMenu();
}
Aggregations