缓存在exoplayer上播放的数据

时间:2015-12-01 08:33:45

标签: android caching mpeg-dash exoplayer

我用MPEG-DASH协议编写了​​一个用于流视频的Android应用程序。 我正在使用Exoplayer,现在我在the demo

上进行测试

我在exoplayer上阅读了有关stackoverflow和问题的一些问题,并为缓存视频编写了此代码

在DashRendererBuilder中(在演示中):

Cache cache = new SimpleCache(context.getCacheDir(), new LeastRecentlyUsedCacheEvictor(1024 * 1024 * 10));
  // Build the video renderer.
  DataSource videoDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
  CacheDataSource videoCacheDataSource= new CacheDataSource(cache, videoDataSource, false, false);
  ChunkSource videoChunkSource= new DashChunkSource(manifestFetcher,
      DefaultDashTrackSelector.newVideoInstance(context, true, filterHdContent),
          videoCacheDataSource, new AdaptiveEvaluator(bandwidthMeter), LIVE_EDGE_LATENCY_MS,
      elapsedRealtimeOffset, mainHandler, player);//*/
  ChunkSampleSource videoSampleSource = new ChunkSampleSource(videoChunkSource, loadControl,
      VIDEO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
      DemoPlayer.TYPE_VIDEO);
  TrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(context, videoSampleSource,
      MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT, 5000, drmSessionManager, true,
      mainHandler, player, 50);

  //cache audio
  Cache cache2 = new SimpleCache(context.getCacheDir(), new LeastRecentlyUsedCacheEvictor(1024 * 1024 * 4));

  // Build the audio renderer.
  DataSource audioDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
  CacheDataSource audioCacheDataSource= new CacheDataSource(cache2, audioDataSource, false, false);
  ChunkSource audioChunkSource = new DashChunkSource(manifestFetcher,
      DefaultDashTrackSelector.newAudioInstance(), audioCacheDataSource, null, LIVE_EDGE_LATENCY_MS,
      elapsedRealtimeOffset, mainHandler, player);
  ChunkSampleSource audioSampleSource = new ChunkSampleSource(audioChunkSource, loadControl,
      AUDIO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
      DemoPlayer.TYPE_AUDIO);
  TrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(audioSampleSource,
      drmSessionManager, true, mainHandler, player, AudioCapabilities.getCapabilities(context));

问题是,当我在缓存数据上寻求前进时,它运作良好。但似乎当我向后查找播放的数据时,数据会丢失并再次下载视频。

我该如何解决这个问题?例如,我想缓存最后两分钟或缓存所有播放的数据,与使用html5时youtube的工作方式相同。

0 个答案:

没有答案