Skip to content

Commit c107a14

Browse files
committed
Implemented playlists #460 #887
1 parent a8d2924 commit c107a14

File tree

23 files changed

+405
-20
lines changed

23 files changed

+405
-20
lines changed

chromecast-receiver/js/io/SenderMessagesDispatcher.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ function SenderMessagesDispatcher(communicationConstants, callbacks) {
1717
callbacks.loadVideo(message.data.videoId, Number(message.data.startSeconds))
1818
else if(message.data.command === communicationConstants.CUE)
1919
callbacks.cueVideo(message.data.videoId, Number(message.data.startSeconds))
20+
else if(message.data.command === communicationConstants.LOAD_PLAYLIST)
21+
callbacks.loadPlaylist(message.data.playlistId, message.data.playlistIndex, Number(message.data.startSeconds))
22+
else if(message.data.command === communicationConstants.CUE_PLAYLIST)
23+
callbacks.cuePlaylist(message.data.playlistId, message.data.playlistIndex, Number(message.data.startSeconds))
2024
else if(message.data.command === communicationConstants.PLAY)
2125
callbacks.playVideo()
2226
else if(message.data.command === communicationConstants.PAUSE)

chromecast-receiver/js/io/YouTubePlayerRemoteBridge.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,28 @@ function YouTubePlayerRemoteBridge(communicationConstants, communicationChannel)
4747
communicationChannel.sendMessage(new YouTubeMessage(communicationConstants.VIDEO_ID, data))
4848
}
4949

50+
function sendPlaylistId(playlist) {
51+
communicationChannel.sendMessage(new YouTubeMessage(communicationConstants.PLAYLIST_ID, playlist))
52+
}
53+
function sendPlaylistIndex(playlist) {
54+
communicationChannel.sendMessage(new YouTubeMessage(communicationConstants.PLAYLIST_INDEX, index))
55+
}
56+
function sendPlaylistType(playlistType) {
57+
communicationChannel.sendMessage(new YouTubeMessage(communicationConstants.PLAYLIST_TYPE, playlistType))
58+
}
59+
function sendPlaylistLength(length) {
60+
communicationChannel.sendMessage(new YouTubeMessage(communicationConstants.PLAYLIST_LENGTH, length))
61+
}
62+
function sendVideoList(videos) {
63+
communicationChannel.sendMessage(new YouTubeMessage(communicationConstants.VIDEO_LIST, videos))
64+
}
65+
function sendLoopStatus(loop) {
66+
communicationChannel.sendMessage(new YouTubeMessage(communicationConstants.LOOP_STATUS, loop))
67+
}
68+
function sendShuffleStatus(shuffle) {
69+
communicationChannel.sendMessage(new YouTubeMessage(communicationConstants.SHUFFLE_STATUS, shuffle))
70+
}
71+
5072
return {
5173
sendYouTubeIframeAPIReady: sendYouTubeIframeAPIReady,
5274
sendReady: sendReady,
@@ -58,6 +80,11 @@ function YouTubePlayerRemoteBridge(communicationConstants, communicationChannel)
5880
sendVideoCurrentTime: sendVideoCurrentTime,
5981
sendVideoDuration: sendVideoDuration,
6082
sendVideoId: sendVideoId,
83+
sendPlaylistIndex: sendPlaylistIndex,
84+
sendPlaylistId: sendPlaylistId,
85+
sendPlaylistType: sendPlaylistType,
86+
sendPlaylistLength: sendPlaylistLength,
87+
sendVideoList: sendVideoList,
6188
}
6289
}
6390

chromecast-sender-sample-app/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ android {
2626
}
2727

2828
namespace 'com.pierfrancescosoffritti.cyplayersample'
29+
compileOptions {
30+
sourceCompatibility JavaVersion.VERSION_17
31+
targetCompatibility JavaVersion.VERSION_17
32+
}
2933
}
3034

3135
dependencies {

chromecast-sender/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ android {
1717
]
1818
}
1919
namespace 'com.pierfrancescosoffritti.androidyoutubeplayer.chromecast.chromecastsender'
20+
compileOptions {
21+
sourceCompatibility JavaVersion.VERSION_17
22+
targetCompatibility JavaVersion.VERSION_17
23+
}
2024
}
2125

2226
dependencies {

chromecast-sender/src/main/java/com/pierfrancescosoffritti/androidyoutubeplayer/chromecast/chromecastsender/ChromecastYouTubePlayer.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,42 @@ class ChromecastYouTubePlayer internal constructor(private val chromecastCommuni
5454
chromecastCommunicationChannel.sendMessage(message)
5555
}
5656

57+
override fun loadPlaylist(videos: List<String>, index: Int, startSeconds: Float) {
58+
TODO("Not yet implemented")
59+
}
60+
61+
override fun loadPlaylist(list: String, listType: String, index: Int, startSeconds: Float) {
62+
TODO("Not yet implemented")
63+
}
64+
65+
override fun cuePlaylist(videos: List<String>, index: Int, startSeconds: Float) {
66+
TODO("Not yet implemented")
67+
}
68+
69+
override fun cuePlaylist(list: String, listType: String, index: Int, startSeconds: Float) {
70+
TODO("Not yet implemented")
71+
}
72+
73+
override fun setLoop(loop: Boolean) {
74+
TODO("Not yet implemented")
75+
}
76+
77+
override fun setShuffle(shuffle: Boolean) {
78+
TODO("Not yet implemented")
79+
}
80+
81+
override fun nextVideo() {
82+
TODO("Not yet implemented")
83+
}
84+
85+
override fun previousVideo() {
86+
TODO("Not yet implemented")
87+
}
88+
89+
override fun playVideoAt(index: Int) {
90+
TODO("Not yet implemented")
91+
}
92+
5793
override fun play() {
5894
val message = JSONUtils.buildFlatJson(
5995
"command" to ChromecastCommunicationConstants.PLAY

chromecast-sender/src/main/java/com/pierfrancescosoffritti/androidyoutubeplayer/chromecast/chromecastsender/io/youtube/ChromecastCommunicationConstants.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.pierfrancescosoffritti.androidyoutubeplayer.chromecast.chromecastsend
66
* Set of constants used for sender-receiver communication. The sender will send the constants to the receiver when a connection is initiated.
77
*/
88
internal object ChromecastCommunicationConstants {
9+
910
// receiver to sender
1011
const val INIT_COMMUNICATION_CONSTANTS = "INIT_COMMUNICATION_CONSTANTS"
1112

@@ -19,10 +20,21 @@ internal object ChromecastCommunicationConstants {
1920
const val VIDEO_CURRENT_TIME = "VIDEO_CURRENT_TIME"
2021
const val VIDEO_DURATION = "VIDEO_DURATION"
2122
const val VIDEO_ID = "VIDEO_ID"
23+
const val PLAYLIST_ID = "PLAYLIST_ID"
24+
const val PLAYLIST_INDEX = "PLAYLIST_INDEX"
25+
const val PLAYLIST_TYPE = "PLAYLIST_TYPE"
26+
const val PLAYLIST_LENGTH = "PLAYLIST_LENGTH"
27+
const val VIDEO_LIST = "VIDEO_LIST"
28+
const val LOOP_STATUS = "LOOP_STATUS"
29+
const val SHUFFLE_STATUS = "SHUFFLE_STATUS"
2230

2331
// sender to receiver
2432
const val LOAD = "LOAD"
33+
const val LOAD_PLAYLIST = "LOAD_PLAYLIST"
34+
const val LOAD_PLAYLIST_OBJ = "LOAD_PLAYLIST_OBJ"
2535
const val CUE = "CUE"
36+
const val CUE_PLAYLIST = "CUE_PLAYLIST"
37+
const val CUE_PLAYLIST_OBJ = "CUE_PLAYLIST_OBJ"
2638
const val PLAY = "PLAY"
2739
const val PAUSE = "PAUSE"
2840
const val SET_VOLUME = "SET_VOLUME"
@@ -42,9 +54,20 @@ internal object ChromecastCommunicationConstants {
4254
VIDEO_CURRENT_TIME to VIDEO_CURRENT_TIME,
4355
VIDEO_DURATION to VIDEO_DURATION,
4456
VIDEO_ID to VIDEO_ID,
57+
PLAYLIST_ID to PLAYLIST_ID,
58+
PLAYLIST_INDEX to PLAYLIST_INDEX,
59+
PLAYLIST_TYPE to PLAYLIST_TYPE,
60+
PLAYLIST_LENGTH to PLAYLIST_LENGTH,
61+
VIDEO_LIST to VIDEO_LIST,
62+
SHUFFLE_STATUS to SHUFFLE_STATUS,
63+
LOOP_STATUS to LOOP_STATUS,
4564

4665
LOAD to LOAD,
66+
LOAD_PLAYLIST to LOAD_PLAYLIST,
67+
LOAD_PLAYLIST_OBJ to LOAD_PLAYLIST_OBJ,
4768
CUE to CUE,
69+
CUE_PLAYLIST to CUE_PLAYLIST,
70+
CUE_PLAYLIST_OBJ to CUE_PLAYLIST_OBJ,
4871
PLAY to PLAY,
4972
PAUSE to PAUSE,
5073
SET_VOLUME to SET_VOLUME,

chromecast-sender/src/main/java/com/pierfrancescosoffritti/androidyoutubeplayer/chromecast/chromecastsender/io/youtube/ChromecastYouTubeMessageDispatcher.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ internal class ChromecastYouTubeMessageDispatcher(
2222
ChromecastCommunicationConstants.VIDEO_CURRENT_TIME -> bridge.sendVideoCurrentTime(messageFromReceiver.data)
2323
ChromecastCommunicationConstants.VIDEO_DURATION -> bridge.sendVideoDuration(messageFromReceiver.data)
2424
ChromecastCommunicationConstants.VIDEO_ID -> bridge.sendVideoId(messageFromReceiver.data)
25+
ChromecastCommunicationConstants.PLAYLIST_ID -> bridge.sendPlaylistId(messageFromReceiver.data)
26+
ChromecastCommunicationConstants.PLAYLIST_TYPE -> bridge.sendPlaylistType(messageFromReceiver.data)
27+
ChromecastCommunicationConstants.PLAYLIST_LENGTH -> bridge.sendPlaylistLength(messageFromReceiver.data)
28+
ChromecastCommunicationConstants.VIDEO_LIST -> bridge.sendVideoList(messageFromReceiver.data)
29+
ChromecastCommunicationConstants.PLAYLIST_INDEX -> bridge.sendPlaylistIndex(messageFromReceiver.data)
2530
}
2631
}
2732
}

core-sample-app/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ android {
2020
}
2121
}
2222

23-
compileOptions {
24-
sourceCompatibility JavaVersion.VERSION_1_8
25-
targetCompatibility JavaVersion.VERSION_1_8
26-
}
2723
packagingOptions {
2824
resources {
2925
// this is needed because I'm importing 2 modules called "core" (core and com.psoffritti.librarysampleapptemplate:core) (https://discuss.kotlinlang.org/t/disable-meta-inf-generation-in-gradle-android-project/3830)
@@ -32,6 +28,10 @@ android {
3228
}
3329

3430
namespace 'com.pierfrancescosoffritti.aytplayersample'
31+
compileOptions {
32+
sourceCompatibility JavaVersion.VERSION_17
33+
targetCompatibility JavaVersion.VERSION_17
34+
}
3535
}
3636

3737
dependencies {

core/build.gradle

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,26 @@ android {
1616
]
1717
}
1818
namespace 'com.pierfrancescosoffritti.androidyoutubeplayer'
19+
20+
compileOptions {
21+
sourceCompatibility JavaVersion.VERSION_17
22+
targetCompatibility JavaVersion.VERSION_17
23+
}
24+
}
25+
26+
java {
27+
toolchain {
28+
languageVersion.set(JavaLanguageVersion.of(17))
29+
}
1930
}
2031

32+
kotlin {
33+
jvmToolchain {
34+
targetCompatibility = JavaVersion.VERSION_17
35+
}
36+
}
37+
38+
2139
dependencies {
2240
testImplementation "junit:junit:$versions.junit"
2341
androidTestImplementation "androidx.test:runner:$versions.runner"

core/src/main/java/com/pierfrancescosoffritti/androidyoutubeplayer/core/player/YouTubePlayer.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@ interface YouTubePlayer {
2020
*/
2121
fun cueVideo(videoId: String, startSeconds: Float)
2222

23+
fun loadPlaylist(videos: List<String>, index: Int, startSeconds: Float)
24+
/**
25+
* @param index Start index. if the index is out of range, youtube will only play the first video on the playlist, then stop.
26+
*/
27+
fun loadPlaylist(list: String, listType: String, index: Int, startSeconds: Float)
28+
29+
fun cuePlaylist(videos: List<String>, index: Int, startSeconds: Float)
30+
/**
31+
* @param index Start index. if the index is out of range, youtube will only play the first video on the playlist, then stop.
32+
*/
33+
fun cuePlaylist(list: String, listType: String, index: Int, startSeconds: Float)
34+
fun setLoop(loop: Boolean)
35+
fun setShuffle(shuffle: Boolean)
36+
fun nextVideo()
37+
fun previousVideo()
38+
fun playVideoAt(index: Int)
39+
2340
fun play()
2441
fun pause()
2542

0 commit comments

Comments
 (0)