From d5d3edbbc2b9eecace3872c95691f8cd97b4968a Mon Sep 17 00:00:00 2001 From: Tomislav Kordic Date: Mon, 22 Jul 2024 17:17:39 +0200 Subject: [PATCH] Cache test in place, failing. --- .../media3/automatedtests/CacheingTest.java | 5 +++-- .../automatedtests/SimplePlayerTestActivity.java | 16 ++++++++-------- .../player/media3/automatedtests/TestBase.java | 1 + .../java/com/mux/player/media/MuxDataSource.kt | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/automatedtests/src/androidTest/java/com/mux/player/media3/automatedtests/CacheingTest.java b/automatedtests/src/androidTest/java/com/mux/player/media3/automatedtests/CacheingTest.java index 05e0cf86..07c87082 100644 --- a/automatedtests/src/androidTest/java/com/mux/player/media3/automatedtests/CacheingTest.java +++ b/automatedtests/src/androidTest/java/com/mux/player/media3/automatedtests/CacheingTest.java @@ -28,7 +28,7 @@ public void init() { urlToPlay = "http://localhost:5000/hls/google_glass/playlist.m3u8"; // These video have larger bitrate, make sure we do not cause any // rebuffering due to low bandwith - bandwidthLimitInBitsPerSecond = 12000000; + bandwidthLimitInBitsPerSecond = 10000000; enableSmartCache = true; super.init(); } @@ -40,7 +40,7 @@ public void testCachedPlayback() { fail("Playback did not start in " + waitForPlaybackToStartInMS + " milliseconds !!!"); } // wait for server to serve first 5 segment. - waitForNSegments(4); + waitForNSegments(8); // Seek to beginning boolean serverServingData = httpServer.isServingData(); if (!serverServingData) { @@ -55,6 +55,7 @@ public void run() { } }); waitForSeekToFinish(); + Thread.sleep(1000); HashMap segmentsAfterSeek = httpServer.getServedSegments(); for (int i = 0; i < 4; i ++) { Thread.sleep(1000); diff --git a/automatedtests/src/androidTest/java/com/mux/player/media3/automatedtests/SimplePlayerTestActivity.java b/automatedtests/src/androidTest/java/com/mux/player/media3/automatedtests/SimplePlayerTestActivity.java index 297113c2..ee151fbb 100644 --- a/automatedtests/src/androidTest/java/com/mux/player/media3/automatedtests/SimplePlayerTestActivity.java +++ b/automatedtests/src/androidTest/java/com/mux/player/media3/automatedtests/SimplePlayerTestActivity.java @@ -98,12 +98,6 @@ protected void onCreate(Bundle savedInstanceState) { playerView = findViewById(R.id.player_view); - initExoPlayer(); - playerView.setPlayer(player); - - // Do not hide controlls - playerView.setControllerShowTimeoutMs(0); - playerView.setControllerHideOnTouch(false); // Setup notification and media session. initAudioSession(); @@ -133,7 +127,7 @@ protected void onDestroy() { } } - public void initExoPlayer() { + public void iniPlayer() { // Hopfully this will not channge the track selection set programmatically ExoTrackSelection.Factory trackSelectionFactory = new AdaptiveTrackSelection.Factory( AdaptiveTrackSelection.DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS * 10, @@ -146,6 +140,7 @@ public void initExoPlayer() { DefaultTrackSelector.Parameters trackSelectorParameters = builder .build(); + // TODO: if this is used somwhere obtaine it from mux player. mediaSourceFactory = new MuxMediaSourceFactory(this, new DefaultDataSource.Factory(this)); trackSelector = new DefaultTrackSelector(/* context= */ this, trackSelectionFactory); trackSelector.setParameters(trackSelectorParameters); @@ -157,17 +152,22 @@ public void initExoPlayer() { player = new MuxPlayer.Builder(this) .plusExoConfig((ExoPlayer.Builder exoBuilder) -> { exoBuilder.setRenderersFactory(renderersFactory); - exoBuilder.setMediaSourceFactory(mediaSourceFactory); +// exoBuilder.setMediaSourceFactory(mediaSourceFactory); exoBuilder.setTrackSelector(trackSelector); }) .addMonitoringData(initMuxSats()) .addExoPlayerBinding(pBinding) .addNetwork(mockNetwork) .enableSmartCache(enableSmartCache) + .enableLogcat(true) .build(); player.addAnalyticsListener(this); playerView.setPlayer(player); + + // Do not hide controlls + playerView.setControllerShowTimeoutMs(0); + playerView.setControllerHideOnTouch(false); } public void initAudioSession() { diff --git a/automatedtests/src/androidTest/java/com/mux/player/media3/automatedtests/TestBase.java b/automatedtests/src/androidTest/java/com/mux/player/media3/automatedtests/TestBase.java index 5b0faa56..5520e567 100644 --- a/automatedtests/src/androidTest/java/com/mux/player/media3/automatedtests/TestBase.java +++ b/automatedtests/src/androidTest/java/com/mux/player/media3/automatedtests/TestBase.java @@ -136,6 +136,7 @@ public void init() { testActivity.setUrlToPlay(urlToPlay); testActivity.setPlayWhenReady(playWhenReady); testActivity.setPlaybackStartPosition(playbackStartPosition); + testActivity.iniPlayer(); testActivity.startPlayback(); pView = testActivity.getPlayerView(); testMediaSource = testActivity.getTestMediaSource(); diff --git a/library/src/main/java/com/mux/player/media/MuxDataSource.kt b/library/src/main/java/com/mux/player/media/MuxDataSource.kt index 6163b7f3..e0880c85 100644 --- a/library/src/main/java/com/mux/player/media/MuxDataSource.kt +++ b/library/src/main/java/com/mux/player/media/MuxDataSource.kt @@ -75,7 +75,7 @@ class MuxDataSource private constructor( override fun open(dataSpec: DataSpec): Long { this.dataSpec = dataSpec; - val readHandle = CacheController.tryRead(dataSpec.uri.toString()) + val readHandle = CacheController.tryRead(dataSpec.uri.toString()) val nowUtc = nowUtc() return if (readHandle == null) {