本文整理匯總了Java中com.google.android.exoplayer2.upstream.DataSource.Factory方法的典型用法代碼示例。如果您正苦於以下問題:Java DataSource.Factory方法的具體用法?Java DataSource.Factory怎麽用?Java DataSource.Factory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.android.exoplayer2.upstream.DataSource
的用法示例。
在下文中一共展示了DataSource.Factory方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCreate
import com.google.android.exoplayer2.upstream.DataSource; //導入方法依賴的package包/類
@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);
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();
}
示例2: startPlayer
import com.google.android.exoplayer2.upstream.DataSource; //導入方法依賴的package包/類
@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();
}
示例3: buildSource
import com.google.android.exoplayer2.upstream.DataSource; //導入方法依賴的package包/類
@Override
protected MediaSource buildSource(HostActivity host, String userAgent,
TransferListener<? super DataSource> mediaTransferListener) {
DataSource.Factory manifestDataSourceFactory = new DefaultDataSourceFactory(host, userAgent);
DataSource.Factory mediaDataSourceFactory = new DefaultDataSourceFactory(host, userAgent,
mediaTransferListener);
Uri manifestUri = Uri.parse(parameters.manifestUrl);
DefaultDashChunkSource.Factory chunkSourceFactory = new DefaultDashChunkSource.Factory(
mediaDataSourceFactory);
return new DashMediaSource(manifestUri, manifestDataSourceFactory, chunkSourceFactory,
MIN_LOADABLE_RETRY_COUNT, 0 /* livePresentationDelayMs */, null, null);
}
示例4: initExoPlayer
import com.google.android.exoplayer2.upstream.DataSource; //導入方法依賴的package包/類
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);
}
示例5: createMediaSource
import com.google.android.exoplayer2.upstream.DataSource; //導入方法依賴的package包/類
private MediaSource createMediaSource(Context context, Uri uri) {
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context,
Util.getUserAgent(context, context.getPackageName()), bandwidthMeter);
DefaultExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
return new ExtractorMediaSource(uri,
dataSourceFactory,
extractorsFactory,
null,
null);
}
示例6: startPlayer
import com.google.android.exoplayer2.upstream.DataSource; //導入方法依賴的package包/類
/**
* 播放啟動視頻
*/
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);
}
示例7: onCreate
import com.google.android.exoplayer2.upstream.DataSource; //導入方法依賴的package包/類
@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);
}
}
示例8: buildMediaSource
import com.google.android.exoplayer2.upstream.DataSource; //導入方法依賴的package包/類
private MediaSource buildMediaSource(Uri uri) {
DashChunkSource.Factory dashChunkSourceFactory = new DefaultDashChunkSource.Factory(
new DefaultHttpDataSourceFactory("ua", BANDWIDTH_METER));
DataSource.Factory manifestDataSourceFactory = new DefaultHttpDataSourceFactory("ua");
return new DashMediaSource.Factory(dashChunkSourceFactory, manifestDataSourceFactory).
createMediaSource(uri);
}
示例9: getDefaultDataSourceFactory
import com.google.android.exoplayer2.upstream.DataSource; //導入方法依賴的package包/類
public static DataSource.Factory getDefaultDataSourceFactory(Context context, DefaultBandwidthMeter bandwidthMeter) {
if (defaultDataSourceFactory == null) {
defaultDataSourceFactory = buildDataSourceFactory(context, bandwidthMeter);
}
return defaultDataSourceFactory;
}
示例10: setDefaultDataSourceFactory
import com.google.android.exoplayer2.upstream.DataSource; //導入方法依賴的package包/類
public static void setDefaultDataSourceFactory(DataSource.Factory factory) {
DataSourceUtil.defaultDataSourceFactory = factory;
}
示例11: SingleSampleMediaSource
import com.google.android.exoplayer2.upstream.DataSource; //導入方法依賴的package包/類
public SingleSampleMediaSource(Uri uri, DataSource.Factory dataSourceFactory, Format format,
long durationUs, int minLoadableRetryCount) {
this(uri, dataSourceFactory, format, durationUs, minLoadableRetryCount, null, null, 0);
}
示例12: HlsMediaSource
import com.google.android.exoplayer2.upstream.DataSource; //導入方法依賴的package包/類
public HlsMediaSource(Uri manifestUri, DataSource.Factory dataSourceFactory,
int minLoadableRetryCount, Handler eventHandler,
AdaptiveMediaSourceEventListener eventListener) {
this(manifestUri, new DefaultHlsDataSourceFactory(dataSourceFactory), minLoadableRetryCount,
eventHandler, eventListener);
}
示例13: getDataSourceFactory
import com.google.android.exoplayer2.upstream.DataSource; //導入方法依賴的package包/類
@Override
public DataSource.Factory getDataSourceFactory() {
//初始化解密工廠類
return new EncryptedFileDataSourceFactory(context,cipher, mSecretKeySpec, mIvParameterSpec);
}
示例14: onCreate
import com.google.android.exoplayer2.upstream.DataSource; //導入方法依賴的package包/類
@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();
}
}
});
}
示例15: buildDataSourceFactory
import com.google.android.exoplayer2.upstream.DataSource; //導入方法依賴的package包/類
/**
* Returns a new DataSource factory.
*
* @param useBandwidthMeter Whether to set {@link #BANDWIDTH_METER} as a listener to the new
* DataSource factory.
* @return A new DataSource factory.
*/
private DataSource.Factory buildDataSourceFactory(boolean useBandwidthMeter) {
return DataSourceUtil.getDefaultDataSourceFactory(getContext(), useBandwidthMeter ? BANDWIDTH_METER : null);
}