Skip to content

Commit

Permalink
Releases/v0.4.0
Browse files Browse the repository at this point in the history
## 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
daytime-em and web-flow authored Mar 7, 2024
1 parent e98e79b commit 7c1c5a2
Show file tree
Hide file tree
Showing 30 changed files with 2,270 additions and 94 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/saucelabs-tests-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ jobs:
runs-on: ubuntu-latest
needs: build

strategy:
max-parallel: 2

env:
app_artifact: automatedtests\/build\/outputs\/apk\/debug\/automatedtests-debug.apk
test_artifact: automatedtests\/build\/outputs\/apk\/androidTest\/debug\/automatedtests-debug-androidTest.apk
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ google-services.json

# automatedtests results
automatedtests/automated_test_results/**

# Test data
*.raw
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ implementation("com.mux.player:android:[Current Version]")

## Play a Mux Video Asset

### Create a MuxExoPlayer
### Create a MuxPlayer

To use the SDK, you must create a `MuxExoPlayer` object using its `Builder`. The basic configuration will enable all of Mux's extra features, and you can make additional config changes using our `Builder`. Almost all of our defaults config options are the same as ExoPlayer's. We only change things about the default configuration when we need to in order to support a Mux Player feature.
To use the SDK, you must create a `MuxPlayer` object using its `Builder`. The basic configuration will enable all of Mux's extra features, and you can make additional config changes using our `Builder`. Almost all of our defaults config options are the same as ExoPlayer's. We only change things about the default configuration when we need to in order to support a Mux Player feature.

```kotlin
val out: MuxExoPlayer = MuxExoPlayer.Builder(context = this)
val out: MuxPlayer = MuxPlayer.Builder(context = this)
.enableLogcat() // Only applies to Mux. Media3 logging is not touched
.applyExoConfig {
// Call ExoPlayer.Builder methods here (but not build()!)
Expand Down

This file was deleted.

5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
android:exported="false"
android:label="Max-Res Modifier"
/>
<activity android:name=".examples.SmartCacheActivity"
android:exported="false"
android:label="Max-Res Modifier"
/>
<activity
android:name=".MainActivity"
android:exported="true"
android:label="Examples"
android:theme="@style/Theme.MuxVideoMedia3.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/mux/player/media3/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.mux.player.media3.databinding.ActivityMainBinding
import com.mux.player.media3.databinding.ListitemExampleBinding
import com.mux.player.media3.examples.BasicPlayerActivity
import com.mux.player.media3.examples.MaxResActivity
import com.mux.player.media3.examples.SmartCacheActivity

class MainActivity : AppCompatActivity() {

Expand Down Expand Up @@ -45,6 +46,10 @@ class MainActivity : AppCompatActivity() {
Example(
title = "Max-Resolution Modifier",
destination = Intent(this@MainActivity, MaxResActivity::class.java)
),
Example(
title = "Smart Caching",
destination = Intent(this@MainActivity, SmartCacheActivity::class.java)
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class BasicPlayerActivity : AppCompatActivity() {
)
.setMediaMetadata(
MediaMetadata.Builder()
.setTitle("Basic MuxExoPlayer Example")
.setTitle("Basic MuxPlayer Example")
.build()
)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class MaxResActivity : AppCompatActivity() {
)
.setMediaMetadata(
MediaMetadata.Builder()
.setTitle("Basic MuxExoPlayer Example")
.setTitle("MuxPlayer Example: Resolution Modifiers")
.build()
)
.build()
Expand Down
120 changes: 120 additions & 0 deletions app/src/main/java/com/mux/player/media3/examples/SmartCacheActivity.kt
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
}
}
2 changes: 1 addition & 1 deletion automatedtests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
minSdkVersion 21
// Target SDK 31 causes manifest merger errors. One of our dependencies is not setting
// `android:exported` for an Activity. Error logs have no more useful information
targetSdkVersion 33 //project.ext.targetSdkVersion
targetSdkVersion 34 //project.ext.targetSdkVersion
versionCode 1
versionName "1.0"
multiDexEnabled true
Expand Down
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 !!!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void startPlayback() {
.setUri(Uri.parse(urlToPlay))
.setMediaMetadata(
new MediaMetadata.Builder()
.setTitle("Basic MuxExoPlayer Example")
.setTitle("Basic MuxPlayer Example")
.build()
)
.build();
Expand Down
Loading

0 comments on commit 7c1c5a2

Please sign in to comment.