-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## New * Added disk caching for Mux Video assets, you can enable it on `MuxPlayer.Builder` (#27) Co-authored-by: Emily Dixon <edixon@mux.com> Co-authored-by: GitHub <noreply@github.com>
- Loading branch information
1 parent
e98e79b
commit 7c1c5a2
Showing
30 changed files
with
2,270 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,6 @@ google-services.json | |
|
||
# automatedtests results | ||
automatedtests/automated_test_results/** | ||
|
||
# Test data | ||
*.raw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
app/src/androidTest/java/com/mux/player/media3/ExampleInstrumentedTest.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
app/src/main/java/com/mux/player/media3/examples/SmartCacheActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package com.mux.player.media3.examples | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import android.util.Log | ||
import android.widget.Toast | ||
import androidx.annotation.OptIn | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.media3.common.MediaMetadata | ||
import androidx.media3.common.PlaybackException | ||
import androidx.media3.common.Player | ||
import androidx.media3.common.util.UnstableApi | ||
import com.mux.stats.sdk.core.model.CustomData | ||
import com.mux.stats.sdk.core.model.CustomerData | ||
import com.mux.stats.sdk.core.model.CustomerVideoData | ||
import com.mux.stats.sdk.core.model.CustomerViewData | ||
import com.mux.stats.sdk.core.util.UUID | ||
import com.mux.player.MuxPlayer | ||
import com.mux.player.media.MediaItems | ||
import com.mux.player.media3.PlaybackIds | ||
import com.mux.player.media3.databinding.ActivityBasicPlayerBinding | ||
|
||
/** | ||
* An example that demonstrates Mux Player's | ||
*/ | ||
class SmartCacheActivity : AppCompatActivity() { | ||
|
||
private lateinit var binding: ActivityBasicPlayerBinding | ||
private val playerView get() = binding.player | ||
|
||
private var player: MuxPlayer? = null | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = ActivityBasicPlayerBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
} | ||
|
||
override fun onStart() { | ||
super.onStart() | ||
|
||
playSomething() | ||
} | ||
|
||
override fun onStop() { | ||
tearDownPlayer() | ||
|
||
super.onStop() | ||
} | ||
|
||
private fun tearDownPlayer() { | ||
playerView.player = null | ||
player?.release() | ||
} | ||
|
||
private fun playSomething() { | ||
val player = createPlayer(this) | ||
val mediaItem = MediaItems.builderFromMuxPlaybackId( | ||
PlaybackIds.TEARS_OF_STEEL, | ||
) | ||
.setMediaMetadata( | ||
MediaMetadata.Builder() | ||
.setTitle("Smart Caching Mux Player Example") | ||
.build() | ||
) | ||
.build() | ||
player.setMediaItem(mediaItem) | ||
player.prepare() | ||
player.playWhenReady = true | ||
|
||
this.playerView.player = player | ||
this.player = player | ||
} | ||
|
||
@OptIn(UnstableApi::class) | ||
private fun createPlayer(context: Context): MuxPlayer { | ||
val out: MuxPlayer = MuxPlayer.Builder(context) | ||
.addMonitoringData( | ||
CustomerData().apply { | ||
customerViewData = CustomerViewData().apply { | ||
viewSessionId = UUID.generateUUID() | ||
} | ||
customerVideoData = CustomerVideoData().apply { | ||
videoSeries = "My Series" | ||
videoId = "abc1234zyxw" | ||
} | ||
customData = CustomData().apply { | ||
customData1 = "my custom metadata field" | ||
customData2 = "another custom metadata field" | ||
customData10 = "up to 10 custom fields" | ||
} | ||
} | ||
) | ||
.applyExoConfig { | ||
// Call ExoPlayer.Builder methods here | ||
setHandleAudioBecomingNoisy(true) | ||
setSeekBackIncrementMs(10_000) | ||
setSeekForwardIncrementMs(30_000) | ||
} | ||
.enableSmartCache(true) | ||
.build() | ||
|
||
out.addListener(object : Player.Listener { | ||
override fun onPlayerError(error: PlaybackException) { | ||
Log.e(TAG, "player error!", error) | ||
Toast.makeText( | ||
this@SmartCacheActivity, | ||
"Playback error! ${error.localizedMessage}", | ||
Toast.LENGTH_LONG | ||
).show() | ||
} | ||
}) | ||
|
||
return out | ||
} | ||
|
||
companion object { | ||
val TAG = SmartCacheActivity::class.simpleName | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
automatedtests/src/androidTest/java/com/mux/player/media3/automatedtests/CachingTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.mux.player.media3.automatedtests; | ||
|
||
import static android.Manifest.permission.READ_EXTERNAL_STORAGE; | ||
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE; | ||
import static androidx.test.rule.GrantPermissionRule.grant; | ||
import static org.junit.Assert.fail; | ||
|
||
import android.Manifest; | ||
import android.os.Environment; | ||
import android.util.Log; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
import androidx.test.filters.LargeTest; | ||
import androidx.test.rule.GrantPermissionRule; | ||
import com.google.common.base.Charsets; | ||
; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Random; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@LargeTest | ||
@RunWith(AndroidJUnit4.class) | ||
public class CachingTests extends TestBase{ | ||
|
||
|
||
@Before | ||
public void init() { | ||
// start proxy server on port 6000, run in seprate thread by default | ||
urlToPlay = "https://stream.mux.com/a4nOgmxGWg6gULfcBbAa00gXyfcwPnAFldF8RdsNyk8M.m3u8"; | ||
super.init(); | ||
} | ||
|
||
@Test | ||
public void testProxyPlayback() { | ||
try { | ||
if (!testActivity.waitForPlaybackToStart(waitForPlaybackToStartInMS )) { | ||
fail("Playback did not start in " + waitForPlaybackToStartInMS + " milliseconds !!!"); | ||
} | ||
Thread.sleep(PLAY_PERIOD_IN_MS); | ||
} catch (Exception e) { | ||
fail(getExceptionFullTraceAndMessage(e)); | ||
} | ||
Log.e(TAG, "All done !!!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.