RemoteMediaClient implemented in example app

- Fix android implementation
This commit is contained in:
gianlucaparadise 2021-11-16 09:00:29 +01:00
parent a4714dfb1b
commit cc5e5f9696
3 changed files with 73 additions and 18 deletions

View file

@ -25,7 +25,7 @@ fun getMediaInfo(mediaInfo: PlatformBridgeApis.MediaInfo?) : MediaInfo? {
val streamType = getStreamType(mediaInfo.streamType)
val metadata = getMediaMetadata(mediaInfo.mediaMetadata)
val mediaTracks = mediaInfo.mediaTracks.map { getMediaTrack(it) }
val customData = JSONObject(mediaInfo.customDataAsJson)
val customData = JSONObject(mediaInfo.customDataAsJson ?: "{}")
return MediaInfo.Builder(mediaInfo.contentId)
.setStreamType(streamType)

View file

@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_cast_framework/cast.dart';
import 'package:flutter_cast_framework/widgets.dart';
import 'media_load_request_data_helper.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@ -18,7 +20,7 @@ class _MyAppState extends State<MyApp> {
final textMessageController = TextEditingController();
final String castNamespace = 'urn:x-cast:cast-your-instructions';
final String castNamespace = 'urn:x-cast:flutter-cast-framework-demo';
@override
void initState() {
@ -48,8 +50,7 @@ class _MyAppState extends State<MyApp> {
void _onSessionStateChanged() {
debugPrint("Session state changed from example");
setState(() {
_sessionState =
castFramework.castContext.sessionManager.state.value;
_sessionState = castFramework.castContext.sessionManager.state.value;
});
}
@ -66,6 +67,11 @@ class _MyAppState extends State<MyApp> {
.sendMessage(castNamespace, message);
}
void _onCastVideo() {
final request = getMediaLoadRequestData();
castFramework.castContext.sessionManager.remoteMediaClient.load(request);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
@ -104,6 +110,10 @@ class _MyAppState extends State<MyApp> {
],
),
Text('Received Message: $_message'),
ElevatedButton(
child: Text('Cast video'),
onPressed: _onCastVideo,
)
],
),
),

View file

@ -0,0 +1,45 @@
import 'package:flutter_cast_framework/cast.dart';
const videoUrl =
"https://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/mp4/BigBuckBunny.mp4";
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() {
final img = WebImage()..url = videoThumb;
final bigImg = WebImage()..url = videoPoster;
final mediaMetadata = MediaMetadata()
..mediaType = MediaType.movie
..webImages = [
img,
bigImg,
];
// final mediaTrack = MediaTrack()
// ..contentId = ""
// ..id = 0
// ..language = ""
// ..name = ""
// ..trackType = TrackType.unknown
// ..trackSubtype = TrackSubtype.unknown;
// final mediaTracks = <MediaTrack>[mediaTrack];
final mediaInfo = MediaInfo()
..contentId = videoUrl
..streamType = StreamType.buffered
..contentType = videoType
..mediaMetadata = mediaMetadata
..mediaTracks = <MediaTrack>[]
..streamDuration = videoDuration;
final request = MediaLoadRequestData()
..shouldAutoplay = true
..currentTime = 0
..mediaInfo = mediaInfo;
return request;
}