Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mute / unMute functions #446

Merged
merged 1 commit into from
Oct 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ class ChromecastYouTubePlayer internal constructor(private val chromecastCommuni

chromecastCommunicationChannel.sendMessage(message)
}
override fun mute() {
val message = JSONUtils.buildFlatJson(
"command" to ChromecastCommunicationConstants.MUTE
)

chromecastCommunicationChannel.sendMessage(message)
}

override fun unMute() {
val message = JSONUtils.buildFlatJson(
"command" to ChromecastCommunicationConstants.UNMUTE
)

chromecastCommunicationChannel.sendMessage(message)
}

override fun setVolume(volumePercent: Int) {
val message = JSONUtils.buildFlatJson(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ internal object ChromecastCommunicationConstants {
const val PAUSE = "PAUSE"
const val SET_VOLUME = "SET_VOLUME"
const val SEEK_TO = "SEEK_TO"
const val MUTE = "MUTE"
const val UNMUTE = "UNMUTE"

fun asJson() = JSONUtils.buildFlatJson(
IFRAME_API_READY to IFRAME_API_READY,
Expand All @@ -45,6 +47,8 @@ internal object ChromecastCommunicationConstants {
PLAY to PLAY,
PAUSE to PAUSE,
SET_VOLUME to SET_VOLUME,
SEEK_TO to SEEK_TO
SEEK_TO to SEEK_TO,
MUTE to MUTE,
UNMUTE to UNMUTE
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ interface YouTubePlayer {
fun play()
fun pause()

fun mute()
fun unMute()

/**
* @param volumePercent Integer between 0 and 100
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ internal class WebViewYouTubePlayer constructor(context: Context, attrs: Attribu
mainThreadHandler.post { loadUrl("javascript:pauseVideo()") }
}

override fun mute() {
mainThreadHandler.post { loadUrl("javascript:mute()") }
}

override fun unMute() {
mainThreadHandler.post { loadUrl("javascript:unMute()") }
}

override fun setVolume(volumePercent: Int) {
if (volumePercent < 0 || volumePercent > 100)
throw IllegalArgumentException("Volume must be between 0 and 100")
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/res/raw/ayp_youtube_player.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@
YouTubePlayerBridge.sendVideoId(videoId);
}

function mute() {
player.mute();
}

function unMute() {
player.unMute();
}

function setVolume(volumePercent) {
player.setVolume(volumePercent);
}
Expand Down