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


Java DataSource類代碼示例

本文整理匯總了Java中com.google.android.exoplayer2.upstream.DataSource的典型用法代碼示例。如果您正苦於以下問題:Java DataSource類的具體用法?Java DataSource怎麽用?Java DataSource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DataSource類屬於com.google.android.exoplayer2.upstream包,在下文中一共展示了DataSource類的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: EncryptedFileDataSourceFactory

import com.google.android.exoplayer2.upstream.DataSource; //導入依賴的package包/類
/**
 * Instantiates a new Encrypted file data source factory.
 *
 * @param context         the context
 * @param cipher          the cipher
 * @param secretKeySpec   the secret key spec
 * @param ivParameterSpec the iv parameter spec
 * @param listener        the listener
 */
public EncryptedFileDataSourceFactory(Context context, Cipher cipher, SecretKeySpec secretKeySpec, IvParameterSpec ivParameterSpec, TransferListener<? super DataSource> listener) {
    mCipher = cipher;
    mSecretKeySpec = secretKeySpec;
    mIvParameterSpec = ivParameterSpec;
    mTransferListener = listener;
    String userAgent = Util.getUserAgent(context, context.getPackageName());
    this.context = context.getApplicationContext();
    this.baseDataSourceFactory = new DefaultDataSourceFactory(context, userAgent);
}
 
開發者ID:yangchaojiang,項目名稱:yjPlay,代碼行數:19,代碼來源:EncryptedFileDataSourceFactory.java

示例3: doInBackground

import com.google.android.exoplayer2.upstream.DataSource; //導入依賴的package包/類
@Override
protected List<SampleGroup> doInBackground(String... uris) {
  List<SampleGroup> result = new ArrayList<>();
  Context context = getApplicationContext();
  String userAgent = Util.getUserAgent(context, "ExoPlayerDemo");
  DataSource dataSource = new DefaultDataSource(context, null, userAgent, false);
  for (String uri : uris) {
    DataSpec dataSpec = new DataSpec(Uri.parse(uri));
    InputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
    try {
      readSampleGroups(new JsonReader(new InputStreamReader(inputStream, "UTF-8")), result);
    } catch (Exception e) {
      Log.e(TAG, "Error loading sample list: " + uri, e);
      sawError = true;
    } finally {
      Util.closeQuietly(dataSource);
    }
  }
  return result;
}
 
開發者ID:ashwanijanghu,項目名稱:ExoPlayer-Offline,代碼行數:21,代碼來源:SampleChooserActivity.java

示例4: CacheDataSource

import com.google.android.exoplayer2.upstream.DataSource; //導入依賴的package包/類
/**
 * Constructs an instance with arbitrary {@link DataSource} and {@link DataSink} instances for
 * reading and writing the cache. One use of this constructor is to allow data to be transformed
 * before it is written to disk.
 *
 * @param cache The cache.
 * @param upstream A {@link DataSource} for reading data not in the cache.
 * @param cacheReadDataSource A {@link DataSource} for reading data from the cache.
 * @param cacheWriteDataSink A {@link DataSink} for writing data to the cache. If null, cache is
 *     accessed read-only.
 * @param flags A combination of {@link #FLAG_BLOCK_ON_CACHE}, {@link #FLAG_IGNORE_CACHE_ON_ERROR}
 *     and {@link #FLAG_IGNORE_CACHE_FOR_UNSET_LENGTH_REQUESTS}, or 0.
 * @param eventListener An optional {@link EventListener} to receive events.
 */
public CacheDataSource(Cache cache, DataSource upstream, DataSource cacheReadDataSource,
    DataSink cacheWriteDataSink, @Flags int flags, @Nullable EventListener eventListener) {
  this.cache = cache;
  this.cacheReadDataSource = cacheReadDataSource;
  this.blockOnCache = (flags & FLAG_BLOCK_ON_CACHE) != 0;
  this.ignoreCacheOnError = (flags & FLAG_IGNORE_CACHE_ON_ERROR) != 0;
  this.ignoreCacheForUnsetLengthRequests =
      (flags & FLAG_IGNORE_CACHE_FOR_UNSET_LENGTH_REQUESTS) != 0;
  this.upstreamDataSource = upstream;
  if (cacheWriteDataSink != null) {
    this.cacheWriteDataSource = new TeeDataSource(upstream, cacheWriteDataSink);
  } else {
    this.cacheWriteDataSource = null;
  }
  this.eventListener = eventListener;
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:31,代碼來源:CacheDataSource.java

示例5: buildMediaSource

import com.google.android.exoplayer2.upstream.DataSource; //導入依賴的package包/類
private MediaSource buildMediaSource(Uri uri, String overrideExtension) {
	DataSource.Factory mediaDataSourceFactory = buildDataSourceFactory(true);
	int type = TextUtils.isEmpty(overrideExtension) ? Util.inferContentType(uri)
			: Util.inferContentType("." + overrideExtension);
	switch (type) {
		case C.TYPE_SS:
			return new SsMediaSource(uri, buildDataSourceFactory(false),
					new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, null);
		case C.TYPE_DASH:
			return new DashMediaSource(uri, buildDataSourceFactory(false),
					new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, null);
		case C.TYPE_HLS:
			return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, null);
		case C.TYPE_OTHER:
			return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(),
					mainHandler, null);
		default: {
			throw new IllegalStateException("Unsupported type: " + type);
		}
	}
}
 
開發者ID:NiciDieNase,項目名稱:chaosflix,代碼行數:22,代碼來源:ExoPlayerFragment.java

示例6: getDataSourceFactory

import com.google.android.exoplayer2.upstream.DataSource; //導入依賴的package包/類
@Override
public DataSource.Factory getDataSourceFactory() {
    //采用默認
    return new DefaultCacheDataSourceFactory(context,100000000,"1234567887654321".getBytes(),eventListener);
    //自定義配置
  /*  LeastRecentlyUsedCacheEvictor evictor = new LeastRecentlyUsedCacheEvictor(100000000);
    SimpleCache simpleCache = new SimpleCache
            //設置你緩存目錄
            (new File(context.getExternalCacheDir(), "media"),
                    //緩存驅逐器
                    evictor,
                    // 緩存文件加密,那麽在使用AES / CBC的文件係統中緩存密鑰將被加密  密鑰必須是16字節長
                    "1234567887654321".getBytes());
    //使用緩存數據源工廠類
    return new DefaultCacheDataSourceFactory(simpleCache,
            //設置下載數據加載工廠類
            new JDefaultDataSourceFactory(context),
            //設置緩存標記
            0
            //最大緩存文件大小,不填寫 默認2m
            4 * 1024 * 1024
            //設置緩存監聽事件
    );*/
    //或者 如果需要監聽事件
    //使用緩存數據源工廠類
   /* return new CacheDataSourceFactory(simpleCache,
            //設置下載數據加載工廠類
            new JDefaultDataSourceFactory(context),
            //緩存讀取數據源工廠
            new FileDataSourceFactory(),
            //緩存數據接收器的工廠
            new CacheDataSinkFactory(simpleCache, CacheDataSource.DEFAULT_MAX_CACHE_FILE_SIZE),
            //設置緩存標記
            0,
            //設置緩存監聽事件
            eventListener);*/
}
 
開發者ID:yangchaojiang,項目名稱:yjPlay,代碼行數:38,代碼來源:OfficeDataSource.java

示例7: createDataSource

import com.google.android.exoplayer2.upstream.DataSource; //導入依賴的package包/類
@Override
public DataSource createDataSource() {
    if (null != mCipher) {
        return new MyDefaultDataSource(context, mCipher, mSecretKeySpec, mIvParameterSpec, mTransferListener, baseDataSourceFactory.createDataSource());
    } else if (key != null) {
        return new Encrypted1FileDataSource(key, new DefaultBandwidthMeter());
    } else {
        return new DefaultDataSource(context, new DefaultBandwidthMeter(), baseDataSourceFactory.createDataSource());
    }
}
 
開發者ID:yangchaojiang,項目名稱:yjPlay,代碼行數:11,代碼來源:EncryptedFileDataSourceFactory.java

示例8: closeQuietly

import com.google.android.exoplayer2.upstream.DataSource; //導入依賴的package包/類
/**
 * Closes a {@link DataSource}, suppressing any {@link IOException} that may occur.
 *
 * @param dataSource The {@link DataSource} to close.
 */
public static void closeQuietly(DataSource dataSource) {
  try {
    if (dataSource != null) {
      dataSource.close();
    }
  } catch (IOException e) {
    // Ignore.
  }
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:15,代碼來源:Util.java

示例9: getDataSource

import com.google.android.exoplayer2.upstream.DataSource; //導入依賴的package包/類
/***
 * 初始化數據源工廠
 * @return DataSource.Factory data source
 */
public DataSource.Factory getDataSource() {
    if (listener != null) {
        return listener.getDataSourceFactory();
    } else {
        return new JDefaultDataSourceFactory(context);
    }
}
 
開發者ID:yangchaojiang,項目名稱:yjPlay,代碼行數:12,代碼來源:MediaSourceBuilder.java

示例10: 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

示例11: 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

示例12: readAndDiscard

import com.google.android.exoplayer2.upstream.DataSource; //導入依賴的package包/類
/**
 * Reads and discards all data specified by the {@code dataSpec}.
 *
 * @param dataSpec Defines the data to be read.
 * @param dataSource The {@link DataSource} to read the data from.
 * @param buffer The buffer to be used while downloading.
 * @param priorityTaskManager If not null it's used to check whether it is allowed to proceed with
 *     caching.
 * @param priority The priority of this task.
 * @return Number of read bytes, or 0 if no data is available because the end of the opened range
 * has been reached.
 */
private static long readAndDiscard(DataSpec dataSpec, DataSource dataSource, byte[] buffer,
    PriorityTaskManager priorityTaskManager, int priority)
    throws IOException, InterruptedException {
  while (true) {
    if (priorityTaskManager != null) {
      // Wait for any other thread with higher priority to finish its job.
      priorityTaskManager.proceed(priority);
    }
    try {
      dataSource.open(dataSpec);
      long totalRead = 0;
      while (true) {
        if (Thread.interrupted()) {
          throw new InterruptedException();
        }
        int read = dataSource.read(buffer, 0, buffer.length);
        if (read == C.RESULT_END_OF_INPUT) {
          return totalRead;
        }
        totalRead += read;
      }
    } catch (PriorityTaskManager.PriorityTooLowException exception) {
      // catch and try again
    } finally {
      Util.closeQuietly(dataSource);
    }
  }
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:41,代碼來源:CacheUtil.java

示例13: 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

示例14: buildMediaSource

import com.google.android.exoplayer2.upstream.DataSource; //導入依賴的package包/類
private MediaSource buildMediaSource(Uri uri) {
  DataSource.Factory manifestDataSourceFactory = new DefaultHttpDataSourceFactory("ua");
  DashChunkSource.Factory dashChunkSourceFactory = new DefaultDashChunkSource.Factory(
      new DefaultHttpDataSourceFactory("ua", BANDWIDTH_METER));
  return new DashMediaSource.Factory(dashChunkSourceFactory, manifestDataSourceFactory)
      .createMediaSource(uri);
}
 
開發者ID:googlecodelabs,項目名稱:exoplayer-intro,代碼行數:8,代碼來源:PlayerActivity.java

示例15: 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


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