當前位置: 首頁>>代碼示例>>Java>>正文


Java DataSource.Factory方法代碼示例

本文整理匯總了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();
}
 
開發者ID:SergeyVinyar,項目名稱:AndroidAudioExample,代碼行數:43,代碼來源:PlayerService.java

示例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();
}
 
開發者ID:vpaliyX,項目名稱:Melophile,代碼行數:18,代碼來源:MediaPlayback21.java

示例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);
}
 
開發者ID:ashwanijanghu,項目名稱:ExoPlayer-Offline,代碼行數:13,代碼來源:DashTest.java

示例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);
}
 
開發者ID:gvsucis,項目名稱:mobile-app-dev-book,代碼行數:16,代碼來源:MediaViewActivity.java

示例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);
}
 
開發者ID:akexorcist,項目名稱:Android-O-Feature,代碼行數:12,代碼來源:PictureInPictureActivity.java

示例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);
}
 
開發者ID:hiliving,項目名稱:P2Video-master,代碼行數:41,代碼來源:PlayerActivity.java

示例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);

    }
}
 
開發者ID:CrazyDude1994,項目名稱:lostfilm-android-client,代碼行數:28,代碼來源:MainActivity.java

示例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);
}
 
開發者ID:googlecodelabs,項目名稱:exoplayer-intro,代碼行數:8,代碼來源:PlayerActivity.java

示例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;
}
 
開發者ID:12d,項目名稱:react-native-videoplayer,代碼行數:7,代碼來源:DataSourceUtil.java

示例10: setDefaultDataSourceFactory

import com.google.android.exoplayer2.upstream.DataSource; //導入方法依賴的package包/類
public static void setDefaultDataSourceFactory(DataSource.Factory factory) {
    DataSourceUtil.defaultDataSourceFactory = factory;
}
 
開發者ID:12d,項目名稱:react-native-videoplayer,代碼行數:4,代碼來源:DataSourceUtil.java

示例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);
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:5,代碼來源:SingleSampleMediaSource.java

示例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);
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:7,代碼來源:HlsMediaSource.java

示例13: getDataSourceFactory

import com.google.android.exoplayer2.upstream.DataSource; //導入方法依賴的package包/類
@Override
public DataSource.Factory getDataSourceFactory() {
    //初始化解密工廠類
    return new EncryptedFileDataSourceFactory(context,cipher, mSecretKeySpec, mIvParameterSpec);
}
 
開發者ID:yangchaojiang,項目名稱:yjPlay,代碼行數:6,代碼來源:EnctyptDataSource.java

示例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();
            }
        }
    });
}
 
開發者ID:garretyoder,項目名稱:Cluttr,代碼行數:50,代碼來源:VideoActivity.java

示例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);
}
 
開發者ID:12d,項目名稱:react-native-videoplayer,代碼行數:11,代碼來源:ReactExoplayerView.java


注:本文中的com.google.android.exoplayer2.upstream.DataSource.Factory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。