Append items to queue in sample
This commit is contained in:
parent
a63e84d5b8
commit
7937df603a
2 changed files with 97 additions and 22 deletions
|
|
@ -113,7 +113,7 @@ class _MyAppState extends State<MyApp> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onCastVideo() {
|
void _onCastVideo() {
|
||||||
final request = getMediaLoadRequestData();
|
final request = getMediaLoadRequestData(mainVideo);
|
||||||
castFramework.castContext.sessionManager.remoteMediaClient.load(request);
|
castFramework.castContext.sessionManager.remoteMediaClient.load(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,6 +139,14 @@ class _MyAppState extends State<MyApp> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _appendToQueue() {
|
||||||
|
final sessionManager = castFramework.castContext.sessionManager;
|
||||||
|
for (var video in otherVideos) {
|
||||||
|
final item = getMediaQueueItem(video);
|
||||||
|
sessionManager.remoteMediaClient.queueAppendItem(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Widget _buildTitle(String text) {
|
Widget _buildTitle(String text) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
|
@ -210,10 +218,18 @@ class _MyAppState extends State<MyApp> {
|
||||||
onPressed: _hasMedia ? _openExpandedControls : null,
|
onPressed: _hasMedia ? _openExpandedControls : null,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
_buildTitle("Queue"),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
child: Text('Queue'),
|
child: Text("Append to Queue"),
|
||||||
|
onPressed: _hasSession ? _appendToQueue : null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: ElevatedButton(
|
||||||
|
child: Text('Show Queue'),
|
||||||
onPressed: _hasSession ? _openQueue : null,
|
onPressed: _hasSession ? _openQueue : null,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,81 @@
|
||||||
import 'package:flutter_cast_framework/cast.dart';
|
import 'package:flutter_cast_framework/cast.dart';
|
||||||
|
|
||||||
const videoUrl =
|
/// in seconds
|
||||||
"https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/mp4/BigBuckBunny.mp4";
|
const double QUEUE_PRELOAD_TIME = 20;
|
||||||
const videoType = "mp4";
|
|
||||||
const videoDuration = 596 * 1000;
|
|
||||||
const videoThumb =
|
|
||||||
"https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/images/480x270/BigBuckBunny.jpg";
|
|
||||||
const videoPoster =
|
|
||||||
"https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/images/780x1200/BigBuckBunny-780x1200.jpg";
|
|
||||||
|
|
||||||
MediaLoadRequestData getMediaLoadRequestData() {
|
const mainVideo = const VideoInfo(
|
||||||
final img = WebImage()..url = videoThumb;
|
"https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/mp4/BigBuckBunny.mp4",
|
||||||
final bigImg = WebImage()..url = videoPoster;
|
"mp4",
|
||||||
|
596 * 1000,
|
||||||
|
"https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/images/480x270/BigBuckBunny.jpg",
|
||||||
|
"https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/images/780x1200/BigBuckBunny-780x1200.jpg",
|
||||||
|
);
|
||||||
|
|
||||||
|
const List<VideoInfo> otherVideos = [
|
||||||
|
const VideoInfo(
|
||||||
|
"https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/mp4/ElephantsDream.mp4",
|
||||||
|
"mp4",
|
||||||
|
653 * 1000,
|
||||||
|
"https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/images/480x270/ElephantsDream.jpg",
|
||||||
|
"https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/images/780x1200/ElephantsDream-780x1200.jpg",
|
||||||
|
),
|
||||||
|
const VideoInfo(
|
||||||
|
"https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/mp4/Sintel.mp4",
|
||||||
|
"mp4",
|
||||||
|
888 * 1000,
|
||||||
|
"https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/images/480x270/Sintel.jpg",
|
||||||
|
"https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/images/780x1200/Sintel-780x1200.jpg",
|
||||||
|
),
|
||||||
|
const VideoInfo(
|
||||||
|
"https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/mp4/TearsOfSteel.mp4",
|
||||||
|
"mp4",
|
||||||
|
734 * 1000,
|
||||||
|
"https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/images/480x270/TearsOfSteel.jpg",
|
||||||
|
"https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/images/780x1200/TearsOfSteel-780x1200.jpg",
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
class VideoInfo {
|
||||||
|
const VideoInfo(
|
||||||
|
this.url,
|
||||||
|
this.type,
|
||||||
|
this.duration,
|
||||||
|
this.thumb,
|
||||||
|
this.poster,
|
||||||
|
);
|
||||||
|
|
||||||
|
final String url;
|
||||||
|
final String type;
|
||||||
|
final int duration;
|
||||||
|
final String thumb;
|
||||||
|
final String poster;
|
||||||
|
}
|
||||||
|
|
||||||
|
MediaLoadRequestData getMediaLoadRequestData(VideoInfo video) {
|
||||||
|
final mediaInfo = _getMediaInfo(video);
|
||||||
|
|
||||||
|
final request = MediaLoadRequestData()
|
||||||
|
..shouldAutoplay = true
|
||||||
|
..currentTime = 0
|
||||||
|
..mediaInfo = mediaInfo;
|
||||||
|
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
MediaQueueItem getMediaQueueItem(VideoInfo video) {
|
||||||
|
final mediaInfo = _getMediaInfo(video);
|
||||||
|
|
||||||
|
final request = MediaQueueItem()
|
||||||
|
..media = mediaInfo
|
||||||
|
..autoplay = false
|
||||||
|
..preloadTime = QUEUE_PRELOAD_TIME;
|
||||||
|
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
MediaInfo _getMediaInfo(VideoInfo video) {
|
||||||
|
final img = WebImage()..url = video.thumb;
|
||||||
|
final bigImg = WebImage()..url = video.poster;
|
||||||
final mediaMetadata = MediaMetadata()
|
final mediaMetadata = MediaMetadata()
|
||||||
..mediaType = MediaType.movie
|
..mediaType = MediaType.movie
|
||||||
..webImages = [
|
..webImages = [
|
||||||
|
|
@ -29,17 +93,12 @@ MediaLoadRequestData getMediaLoadRequestData() {
|
||||||
// final mediaTracks = <MediaTrack>[mediaTrack];
|
// final mediaTracks = <MediaTrack>[mediaTrack];
|
||||||
|
|
||||||
final mediaInfo = MediaInfo()
|
final mediaInfo = MediaInfo()
|
||||||
..contentId = videoUrl
|
..contentId = video.url
|
||||||
..streamType = StreamType.buffered
|
..streamType = StreamType.buffered
|
||||||
..contentType = videoType
|
..contentType = video.type
|
||||||
..mediaMetadata = mediaMetadata
|
..mediaMetadata = mediaMetadata
|
||||||
..mediaTracks = <MediaTrack>[]
|
..mediaTracks = <MediaTrack>[]
|
||||||
..streamDuration = videoDuration;
|
..streamDuration = video.duration;
|
||||||
|
|
||||||
final request = MediaLoadRequestData()
|
return mediaInfo;
|
||||||
..shouldAutoplay = true
|
|
||||||
..currentTime = 0
|
|
||||||
..mediaInfo = mediaInfo;
|
|
||||||
|
|
||||||
return request;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue