|
| 1 | +/* |
| 2 | + * Copyright (c) SRG SSR. All rights reserved. |
| 3 | + * License information is available from the LICENSE file. |
| 4 | + */ |
| 5 | +package ch.srgssr.pillarbox.player |
| 6 | + |
| 7 | +import android.net.Uri |
| 8 | +import android.os.Looper |
| 9 | +import androidx.media3.common.MediaItem |
| 10 | +import androidx.media3.common.Player |
| 11 | +import androidx.media3.test.utils.FakeClock |
| 12 | +import androidx.media3.test.utils.robolectric.TestPlayerRunHelper |
| 13 | +import androidx.test.core.app.ApplicationProvider |
| 14 | +import org.junit.runner.RunWith |
| 15 | +import org.robolectric.ParameterizedRobolectricTestRunner |
| 16 | +import org.robolectric.ParameterizedRobolectricTestRunner.Parameters |
| 17 | +import org.robolectric.Shadows.shadowOf |
| 18 | +import kotlin.test.AfterTest |
| 19 | +import kotlin.test.BeforeTest |
| 20 | +import kotlin.test.Test |
| 21 | +import kotlin.test.assertEquals |
| 22 | +import kotlin.test.assertNotNull |
| 23 | +import kotlin.test.assertTrue |
| 24 | + |
| 25 | +@RunWith(ParameterizedRobolectricTestRunner::class) |
| 26 | +class IsPlayingAllTypeOfContentTest( |
| 27 | + private val urlToTest: String |
| 28 | +) { |
| 29 | + private lateinit var player: PillarboxPlayer |
| 30 | + |
| 31 | + @BeforeTest |
| 32 | + fun setUp() { |
| 33 | + player = PillarboxPlayer( |
| 34 | + context = ApplicationProvider.getApplicationContext(), |
| 35 | + clock = FakeClock(true), |
| 36 | + ) |
| 37 | + } |
| 38 | + |
| 39 | + @AfterTest |
| 40 | + fun tearDown() { |
| 41 | + player.release() |
| 42 | + |
| 43 | + shadowOf(Looper.getMainLooper()).idle() |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + fun `is playing`() { |
| 48 | + player.addMediaItem(MediaItem.fromUri(urlToTest)) |
| 49 | + player.prepare() |
| 50 | + player.play() |
| 51 | + |
| 52 | + TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY) |
| 53 | + |
| 54 | + // Make test flaky because dependant of internet |
| 55 | + if (player.playerError != null) { |
| 56 | + throw IllegalStateException(player.playerError) |
| 57 | + } |
| 58 | + |
| 59 | + assertEquals(Player.STATE_READY, player.playbackState) |
| 60 | + assertTrue(player.isPlaying) |
| 61 | + assertNotNull(player.currentMediaItem) |
| 62 | + assertEquals(player.currentMediaItem?.localConfiguration?.uri, Uri.parse(urlToTest)) |
| 63 | + } |
| 64 | + |
| 65 | + companion object { |
| 66 | + // From urn:swi:video:48940210 |
| 67 | + private const val VOD_MP4 = |
| 68 | + "https://cdn.prod.swi-services.ch/video-projects/141b30ce-3850-424b-9063-a20d5619d342/localised-videos/ENG/renditions/ENG.mp4" |
| 69 | + private const val VOD_HLS = "https://swi-vod.akamaized.net/videoJson/47603186/master.m3u8" |
| 70 | + private const val AOD_MP3 = "https://srfaudio-a.akamaihd.net/delivery/world/af671f12-6f17-415a-9dd8-b8aee24cce8b.mp3" |
| 71 | + private const val VOD_DASH_H264 = "https://storage.googleapis.com/wvmedia/clear/h264/tears/tears.mpd" |
| 72 | + private const val VOD_DASH_H265 = "https://storage.googleapis.com/wvmedia/clear/hevc/tears/tears.mpd" |
| 73 | + private const val LIVE_HLS = "https://rtsc3video.akamaized.net/hls/live/2042837/c3video/3/playlist.m3u8?dw=0" |
| 74 | + private const val LIVE_DVR_HLS = "https://rtsc3video.akamaized.net/hls/live/2042837/c3video/3/playlist.m3u8" |
| 75 | + private const val AUDIO_LIVE_MP3 = "https://stream.srg-ssr.ch/m/la-1ere/mp3_128" |
| 76 | + private const val AUDIO_LIVE_DVR_HLS = "https://lsaplus.swisstxt.ch/audio/couleur3_96.stream/playlist.m3u8" |
| 77 | + |
| 78 | + @JvmStatic |
| 79 | + @Suppress("unused") |
| 80 | + @Parameters(name = "{index}: {0}") |
| 81 | + fun parameters(): Iterable<Any> { |
| 82 | + return listOf( |
| 83 | + VOD_MP4, |
| 84 | + VOD_HLS, |
| 85 | + AOD_MP3, |
| 86 | + VOD_DASH_H264, |
| 87 | + VOD_DASH_H265, |
| 88 | + LIVE_HLS, |
| 89 | + LIVE_DVR_HLS, |
| 90 | + AUDIO_LIVE_MP3, |
| 91 | + AUDIO_LIVE_DVR_HLS, |
| 92 | + ) |
| 93 | + } |
| 94 | + } |
| 95 | +} |
0 commit comments