Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/0.0.17'
Browse files Browse the repository at this point in the history
  • Loading branch information
UelitonFreitas committed Jul 31, 2017
2 parents 69d2a28 + ef089a7 commit e5f5be2
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 65 deletions.
6 changes: 4 additions & 2 deletions app/src/main/kotlin/io/clappr/player/app/PlayerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import io.clappr.player.base.Event
import io.clappr.player.base.Options
import io.clappr.player.log.Logger

class PlayerActivity : Activity() {
class PlayerActivity : Activity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_player)

val player = Player()
player.configure(Options(source = "http://clappr.io/highline.mp4", autoPlay = true))
player.configure(Options(source = "http://clappr.io/highline.mp4"))
player.on(Event.WILL_PLAY.value, Callback.wrap { Logger.info("Will Play", "App") })
player.on(Event.PLAYING.value, Callback.wrap { Logger.info("Playing", "App") })
player.on(Event.DID_COMPLETE.value, Callback.wrap { Logger.info("Completed", "App") })
Expand All @@ -26,6 +26,8 @@ class PlayerActivity : Activity() {
val fragmentTransaction = fragmentManager.beginTransaction()
fragmentTransaction.add(R.id.container, player)
fragmentTransaction.commit()

player.play()
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
Expand Down
2 changes: 1 addition & 1 deletion clappr/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ apply plugin: 'com.github.dcendents.android-maven'
apply from: 'versioning.gradle'

group = 'io.clappr.player'
version = '0.0.16'
version = '0.0.17'

bintray {
user = System.getenv('BINTRAY_USER')
Expand Down
1 change: 0 additions & 1 deletion clappr/src/main/kotlin/io/clappr/player/Player.kt
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ open class Player(private val base: BaseObject = BaseObject()) : Fragment(), Eve
// TODO: Use container load instead of a new Player configuration
core?.let {
val options = it.options
options.autoPlay = true
options.source = source
options.mimeType = mimeType
configure(options)
Expand Down
3 changes: 0 additions & 3 deletions clappr/src/main/kotlin/io/clappr/player/base/Options.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import java.util.*
class Options(
var source: String? = null,
var mimeType: String? = null,
@Deprecated(message = "Autoplay functionality will be removed from Player on June/15/2017",
level = DeprecationLevel.WARNING)
var autoPlay: Boolean = true,
val options: HashMap<String, Any> = hashMapOf<String, Any>()) : MutableMap<String, Any> by options

enum class ClapprOption(val value: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,8 @@ abstract class Playback(var source: String, var mimeType: String? = null, val op
})
}

if (options.autoPlay) {
if (!play()) {
once(Event.READY.value, Callback.wrap { play() })
}
if (!play()) {
once(Event.READY.value, Callback.wrap { play() })
}
return this
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ open class ExoPlayerPlayback(source: String, mimeType: String? = null, options:
}
}

private fun checkInitialMedias(){
private fun checkInitialMedias() {
options.options[ClapprOption.SELECTED_MEDIA_OPTIONS.value]?.let {
setupInitialMediasFromClapprOptions()
}
Expand Down Expand Up @@ -380,26 +380,25 @@ open class ExoPlayerPlayback(source: String, mimeType: String? = null, options:
subtitlesFromOptions?.forEach {
val textFormat = Format.createTextSampleFormat(null, MimeTypes.APPLICATION_SUBRIP, null, Format.NO_VALUE, Format.NO_VALUE, it.key, null)
val subtitleSource = SingleSampleMediaSource(Uri.parse(it.value), dataSourceFactory, textFormat, C.TIME_UNSET)
addAvailableMediaOption(createSubtitleMediaOption(textFormat, subtitleSource))

createSubtitleMediaOption(textFormat, subtitleSource)?.let { addAvailableMediaOption(it) }
}
}

private fun setUpOptions(renderedIndex: Int, trackGroups: MappingTrackSelector.MappedTrackInfo, block: (format: Format, mediaInfo: Options) -> MediaOption?) {
private fun setUpOptions(renderedIndex: Int, trackGroups: MappingTrackSelector.MappedTrackInfo, createMediaOption: (format: Format, mediaInfo: Options) -> MediaOption?) {
trackGroups.forEachGroupIndexed(renderedIndex) { index, trackGroup ->
addOptions(renderedIndex, index, trackGroup, block)
addOptions(renderedIndex, index, trackGroup, createMediaOption)
}
}

private fun addOptions(renderedIndex: Int, trackGroupIndex: Int, trackGroup: TrackGroup, block: (format: Format, mediaInfo: Options) -> MediaOption?) {
private fun addOptions(renderedIndex: Int, trackGroupIndex: Int, trackGroup: TrackGroup, createMediaOption: (format: Format, mediaInfo: Options) -> MediaOption?) {
trackGroup.forEachFormatIndexed { index, format ->
format.language?.let {
val mediaInfo = createMediaInfo(renderedIndex, trackGroupIndex, index)
val mediaOption = block(format, mediaInfo)
val mediaInfo = createMediaInfo(renderedIndex, trackGroupIndex, index)
val mediaOption = createMediaOption(format, mediaInfo)

mediaOption?.let {
addAvailableMediaOption(mediaOption)
selectActualSelectedMediaOption(renderedIndex, format, mediaOption)
}
mediaOption?.let {
addAvailableMediaOption(mediaOption)
selectActualSelectedMediaOption(renderedIndex, format, mediaOption)
}
}
}
Expand All @@ -411,22 +410,27 @@ open class ExoPlayerPlayback(source: String, mimeType: String? = null, options:
}
}

private fun createAudioMediaOption(format: Format, mediaInfo: Options): MediaOption? {
return when (format.language) {
"und" -> MediaOption(MediaOptionType.Audio.ORIGINAL.value, MediaOptionType.AUDIO, mediaInfo, null)
"pt" -> MediaOption(MediaOptionType.Audio.PT_BR.value, MediaOptionType.AUDIO, mediaInfo, null)
private fun createAudioMediaOption(format: Format, mediaInfo: Options): MediaOption {
return format.language?.let { createAudioMediaOptionFromLanguage(it, mediaInfo) } ?: createOriginalOption(mediaInfo)
}

private fun createAudioMediaOptionFromLanguage(language: String, mediaInfo: Options): MediaOption {
return when (language.toLowerCase()) {
"und" -> createOriginalOption(mediaInfo)
"pt", "por" -> MediaOption(MediaOptionType.Audio.PT_BR.value, MediaOptionType.AUDIO, mediaInfo, null)
"en" -> MediaOption(MediaOptionType.Audio.EN.value, MediaOptionType.AUDIO, mediaInfo, null)
null -> createAudioOffOption(mediaInfo)
else -> MediaOption(format.language, MediaOptionType.AUDIO, mediaInfo, null)
else -> MediaOption(language, MediaOptionType.AUDIO, mediaInfo, null)
}
}

private fun createAudioOffOption(mediaInfo: Options) = MediaOption(MediaOptionType.Audio.ORIGINAL.value, MediaOptionType.AUDIO, mediaInfo, null)
private fun createOriginalOption(raw: Any?) = MediaOption(MediaOptionType.Audio.ORIGINAL.value, MediaOptionType.AUDIO, raw, null)

private fun createSubtitleMediaOption(format: Format, raw: Any?) = format.language?.let { createSubtitleMediaOptionFromLanguage(it, raw) }

private fun createSubtitleMediaOption(format: Format, raw: Any?): MediaOption {
val mediaOption = when (format.language) {
"pt" -> MediaOption(MediaOptionType.Language.PT_BR.value, MediaOptionType.SUBTITLE, raw, null)
else -> MediaOption(format.language, MediaOptionType.SUBTITLE, raw, null)
private fun createSubtitleMediaOptionFromLanguage(language: String, raw: Any?): MediaOption {
val mediaOption = when (language.toLowerCase()) {
"pt", "por" -> MediaOption(MediaOptionType.Language.PT_BR.value, MediaOptionType.SUBTITLE, raw, null)
else -> MediaOption(language, MediaOptionType.SUBTITLE, raw, null)
}

return mediaOption
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,8 @@ class MediaPlayerPlayback(source: String, mimeType: String? = null, options: Opt
}

override fun render() : UIObject {
if (options.autoPlay) {
if (!play()) {
this.once(Event.READY.value, Callback.wrap { bundle: Bundle? -> play() })
}
if (!play()) {
this.once(Event.READY.value, Callback.wrap { bundle: Bundle? -> play() })
}

return this
Expand Down
39 changes: 15 additions & 24 deletions clappr/src/test/kotlin/io/clappr/player/components/PlaybackTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import kotlin.collections.HashMap
open class PlaybackTest {


class SomePlayback(source: String, options: Options = Options()): Playback(source, null, options) {
companion object: PlaybackSupportInterface {
class SomePlayback(source: String, options: Options = Options()) : Playback(source, null, options) {
companion object : PlaybackSupportInterface {
val validSource = "valid-source.mp4"
override val name = ""

Expand All @@ -40,12 +40,12 @@ open class PlaybackTest {

@Before
fun setup() {
BaseObject.context = ShadowApplication.getInstance().applicationContext
BaseObject.context = ShadowApplication.getInstance().applicationContext
}

@Test(expected = IllegalArgumentException::class)
fun shouldThrowWhenInstantiatingWithInvalidSource() {
object: Playback("some-invalid-source.mp4") {}
object : Playback("some-invalid-source.mp4") {}
}

@Test
Expand All @@ -62,18 +62,11 @@ open class PlaybackTest {

@Test
fun shouldCallPlayWhenOptionsHaveAutoplayOn() {
val playback = SomePlayback("valid-source.mp4", Options(autoPlay = true))
val playback = SomePlayback("valid-source.mp4", Options())
playback.render()
assertTrue("play should be called when autoplay is on", playback.playWasCalled)
}

@Test
fun shouldNotCallPlayWhenOptionsHaveAutoplayOff() {
val playback = SomePlayback("valid-source.mp4", Options(autoPlay = false))
playback.render()
assertFalse("play should not be called when autoplay is off", playback.playWasCalled)
}

@Test
fun shouldStopListeningOnDestroy() {
val triggerObject = BaseObject()
Expand Down Expand Up @@ -117,7 +110,7 @@ open class PlaybackTest {
}

private fun checkAvailableMedia(mediaOptionType: MediaOptionType){
val playback = SomePlayback("valid-source.mp4", Options(autoPlay = false))
val playback = SomePlayback("valid-source.mp4", Options())
val quantity = 10
val mediaOptionList = insertMedia(playback, mediaOptionType, quantity)

Expand All @@ -130,8 +123,8 @@ open class PlaybackTest {
assertTrue(playback.hasMediaOptionAvailable)
}

private fun insertMedia(playback: Playback, mediaOptionType: MediaOptionType, quantity: Int) : MutableList<MediaOption>{
val mediaOptionList : MutableList<MediaOption> = ArrayList()
private fun insertMedia(playback: Playback, mediaOptionType: MediaOptionType, quantity: Int): MutableList<MediaOption> {
val mediaOptionList: MutableList<MediaOption> = ArrayList()
for (i in 1..quantity) {
val mediaOption = MediaOption("Name $i", mediaOptionType, i, null)
playback.addAvailableMediaOption(mediaOption)
Expand All @@ -151,11 +144,9 @@ open class PlaybackTest {
testSetSelectedMediaOption(MediaOptionType.SUBTITLE)
}

private fun testSetSelectedMediaOption(mediaOptionType: MediaOptionType){
val playback = SomePlayback("valid-source.mp4", Options(autoPlay = false))
val random = Random()
val randomNumber = random.nextInt(10)
val mediaOptionList = insertMedia(playback, mediaOptionType, randomNumber)
private fun testSetSelectedMediaOption(mediaOptionType: MediaOptionType) {
val playback = SomePlayback("valid-source.mp4")
val mediaOptionList = insertMedia(playback, mediaOptionType, 3)

mediaOptionList.forEach {
playback.setSelectedMediaOption(it)
Expand All @@ -165,7 +156,7 @@ open class PlaybackTest {

@Test
fun shouldResetAvailableMediaOptions() {
val playback = SomePlayback("valid-source.mp4", Options(autoPlay = false))
val playback = SomePlayback("valid-source.mp4", Options())
val random = Random()
val randomNumber = random.nextInt(10)
insertMedia(playback, MediaOptionType.SUBTITLE, randomNumber)
Expand All @@ -179,7 +170,7 @@ open class PlaybackTest {

@Test
fun shouldReturnNoOneSelectedMediaOption(){
val playback = SomePlayback("valid-source.mp4", Options(autoPlay = false))
val playback = SomePlayback("valid-source.mp4", Options())

playback.setSelectedMediaOption(MediaOption("Name", MediaOptionType.SUBTITLE, "name", null))
val mediaSelectedAudio = playback.selectedMediaOption(MediaOptionType.AUDIO)
Expand All @@ -189,7 +180,7 @@ open class PlaybackTest {

@Test
fun shouldTriggerMediaOptionsUpdateEvents() {
val playback = SomePlayback("valid-source.mp4", Options(autoPlay = false))
val playback = SomePlayback("valid-source.mp4", Options())

val listenObject = BaseObject()

Expand Down Expand Up @@ -260,7 +251,7 @@ open class PlaybackTest {
val options = Options(options = hashMap)
val playback = SomePlayback("valid-source.mp4", options)
playback.setupInitialMediasFromClapprOptions()
} catch (ex: Exception){
} catch (ex: Exception) {
fail("Exception: ${ex.message}")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ open class MediaPlayerPlaybackTest {
validMedia = ShadowMediaPlayer.MediaInfo(1000,0)
ShadowMediaPlayer.addMediaInfo(DataSource.toDataSource("valid"), validMedia)

mediaPlayerPlayback = MediaPlayerPlayback(source = "valid", options = Options(autoPlay = false))
mediaPlayerPlayback = MediaPlayerPlayback(source = "valid", options = Options())
createSurface(mediaPlayerPlayback)
mediaPlayerPlayback.render()
}

private fun createSurface(mpp: MediaPlayerPlayback) {
Expand Down Expand Up @@ -138,6 +137,7 @@ open class MediaPlayerPlaybackTest {

mediaPlayerPlayback.play()

scheduler.advanceBy(200)
assertEquals("will play triggered", 1, willPlayCount)
assertEquals("playing not triggered", 1, playingCount)
}
Expand Down Expand Up @@ -255,7 +255,7 @@ open class MediaPlayerPlaybackTest {

@Test
fun shouldHandleAutoplay() {
val mpp = MediaPlayerPlayback(source = "valid", options = Options(autoPlay = true))
val mpp = MediaPlayerPlayback(source = "valid", options = Options())
createSurface(mpp)
mpp.render()

Expand Down

0 comments on commit e5f5be2

Please sign in to comment.