RemoteMediaClient implemented in example app
- Fix android implementation
This commit is contained in:
parent
a4714dfb1b
commit
cc5e5f9696
3 changed files with 73 additions and 18 deletions
|
|
@ -9,7 +9,7 @@ import com.google.android.gms.cast.MediaTrack
|
||||||
import com.google.android.gms.common.images.WebImage
|
import com.google.android.gms.common.images.WebImage
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
|
||||||
fun getMediaLoadRequestData(request: PlatformBridgeApis.MediaLoadRequestData) : MediaLoadRequestData {
|
fun getMediaLoadRequestData(request: PlatformBridgeApis.MediaLoadRequestData): MediaLoadRequestData {
|
||||||
val mediaInfo = getMediaInfo(request.mediaInfo)
|
val mediaInfo = getMediaInfo(request.mediaInfo)
|
||||||
|
|
||||||
return MediaLoadRequestData.Builder()
|
return MediaLoadRequestData.Builder()
|
||||||
|
|
@ -19,13 +19,13 @@ fun getMediaLoadRequestData(request: PlatformBridgeApis.MediaLoadRequestData) :
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMediaInfo(mediaInfo: PlatformBridgeApis.MediaInfo?) : MediaInfo? {
|
fun getMediaInfo(mediaInfo: PlatformBridgeApis.MediaInfo?): MediaInfo? {
|
||||||
if (mediaInfo == null) return null
|
if (mediaInfo == null) return null
|
||||||
|
|
||||||
val streamType = getStreamType(mediaInfo.streamType)
|
val streamType = getStreamType(mediaInfo.streamType)
|
||||||
val metadata = getMediaMetadata(mediaInfo.mediaMetadata)
|
val metadata = getMediaMetadata(mediaInfo.mediaMetadata)
|
||||||
val mediaTracks = mediaInfo.mediaTracks.map { getMediaTrack(it) }
|
val mediaTracks = mediaInfo.mediaTracks.map { getMediaTrack(it) }
|
||||||
val customData = JSONObject(mediaInfo.customDataAsJson)
|
val customData = JSONObject(mediaInfo.customDataAsJson ?: "{}")
|
||||||
|
|
||||||
return MediaInfo.Builder(mediaInfo.contentId)
|
return MediaInfo.Builder(mediaInfo.contentId)
|
||||||
.setStreamType(streamType)
|
.setStreamType(streamType)
|
||||||
|
|
@ -37,7 +37,7 @@ fun getMediaInfo(mediaInfo: PlatformBridgeApis.MediaInfo?) : MediaInfo? {
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getStreamType(streamType: PlatformBridgeApis.StreamType) : Int {
|
fun getStreamType(streamType: PlatformBridgeApis.StreamType): Int {
|
||||||
return when (streamType) {
|
return when (streamType) {
|
||||||
PlatformBridgeApis.StreamType.invalid -> -1
|
PlatformBridgeApis.StreamType.invalid -> -1
|
||||||
PlatformBridgeApis.StreamType.none -> 0
|
PlatformBridgeApis.StreamType.none -> 0
|
||||||
|
|
@ -46,7 +46,7 @@ fun getStreamType(streamType: PlatformBridgeApis.StreamType) : Int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMediaMetadata(mediaMetadata: PlatformBridgeApis.MediaMetadata) : MediaMetadata {
|
fun getMediaMetadata(mediaMetadata: PlatformBridgeApis.MediaMetadata): MediaMetadata {
|
||||||
val mediaType = getMediaType(mediaMetadata.mediaType)
|
val mediaType = getMediaType(mediaMetadata.mediaType)
|
||||||
val result = MediaMetadata(mediaType)
|
val result = MediaMetadata(mediaType)
|
||||||
|
|
||||||
|
|
@ -64,7 +64,7 @@ fun getMediaMetadata(mediaMetadata: PlatformBridgeApis.MediaMetadata) : MediaMet
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMediaType(mediaType: PlatformBridgeApis.MediaType) : Int {
|
fun getMediaType(mediaType: PlatformBridgeApis.MediaType): Int {
|
||||||
return when (mediaType) {
|
return when (mediaType) {
|
||||||
PlatformBridgeApis.MediaType.generic -> 0
|
PlatformBridgeApis.MediaType.generic -> 0
|
||||||
PlatformBridgeApis.MediaType.movie -> 1
|
PlatformBridgeApis.MediaType.movie -> 1
|
||||||
|
|
@ -109,7 +109,7 @@ fun getMediaType(mediaType: PlatformBridgeApis.MediaType) : Int {
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
fun getMediaTrack(mediaTrack: PlatformBridgeApis.MediaTrack) : MediaTrack {
|
fun getMediaTrack(mediaTrack: PlatformBridgeApis.MediaTrack): MediaTrack {
|
||||||
val trackType = getTrackType(mediaTrack.trackType)
|
val trackType = getTrackType(mediaTrack.trackType)
|
||||||
val trackSubtype = getTrackSubtype(mediaTrack.trackSubtype)
|
val trackSubtype = getTrackSubtype(mediaTrack.trackSubtype)
|
||||||
|
|
||||||
|
|
@ -120,7 +120,7 @@ fun getMediaTrack(mediaTrack: PlatformBridgeApis.MediaTrack) : MediaTrack {
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTrackType(trackType: PlatformBridgeApis.TrackType) : Int {
|
fun getTrackType(trackType: PlatformBridgeApis.TrackType): Int {
|
||||||
return when (trackType) {
|
return when (trackType) {
|
||||||
PlatformBridgeApis.TrackType.unknown -> 0
|
PlatformBridgeApis.TrackType.unknown -> 0
|
||||||
PlatformBridgeApis.TrackType.text -> 1
|
PlatformBridgeApis.TrackType.text -> 1
|
||||||
|
|
@ -129,14 +129,14 @@ fun getTrackType(trackType: PlatformBridgeApis.TrackType) : Int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTrackSubtype(trackSubtype: PlatformBridgeApis.TrackSubtype) : Int {
|
fun getTrackSubtype(trackSubtype: PlatformBridgeApis.TrackSubtype): Int {
|
||||||
return when (trackSubtype) {
|
return when (trackSubtype) {
|
||||||
PlatformBridgeApis.TrackSubtype.unknown -> -1
|
PlatformBridgeApis.TrackSubtype.unknown -> -1
|
||||||
PlatformBridgeApis.TrackSubtype.none -> 0
|
PlatformBridgeApis.TrackSubtype.none -> 0
|
||||||
PlatformBridgeApis.TrackSubtype.subtitles -> 1
|
PlatformBridgeApis.TrackSubtype.subtitles -> 1
|
||||||
PlatformBridgeApis.TrackSubtype.captions -> 2
|
PlatformBridgeApis.TrackSubtype.captions -> 2
|
||||||
PlatformBridgeApis.TrackSubtype.descriptions -> 3
|
PlatformBridgeApis.TrackSubtype.descriptions -> 3
|
||||||
PlatformBridgeApis.TrackSubtype.chapters -> 4
|
PlatformBridgeApis.TrackSubtype.chapters -> 4
|
||||||
PlatformBridgeApis.TrackSubtype.metadata -> 5
|
PlatformBridgeApis.TrackSubtype.metadata -> 5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_cast_framework/cast.dart';
|
import 'package:flutter_cast_framework/cast.dart';
|
||||||
import 'package:flutter_cast_framework/widgets.dart';
|
import 'package:flutter_cast_framework/widgets.dart';
|
||||||
|
|
||||||
|
import 'media_load_request_data_helper.dart';
|
||||||
|
|
||||||
void main() => runApp(MyApp());
|
void main() => runApp(MyApp());
|
||||||
|
|
||||||
class MyApp extends StatefulWidget {
|
class MyApp extends StatefulWidget {
|
||||||
|
|
@ -18,7 +20,7 @@ class _MyAppState extends State<MyApp> {
|
||||||
|
|
||||||
final textMessageController = TextEditingController();
|
final textMessageController = TextEditingController();
|
||||||
|
|
||||||
final String castNamespace = 'urn:x-cast:cast-your-instructions';
|
final String castNamespace = 'urn:x-cast:flutter-cast-framework-demo';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
|
@ -48,8 +50,7 @@ class _MyAppState extends State<MyApp> {
|
||||||
void _onSessionStateChanged() {
|
void _onSessionStateChanged() {
|
||||||
debugPrint("Session state changed from example");
|
debugPrint("Session state changed from example");
|
||||||
setState(() {
|
setState(() {
|
||||||
_sessionState =
|
_sessionState = castFramework.castContext.sessionManager.state.value;
|
||||||
castFramework.castContext.sessionManager.state.value;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,6 +67,11 @@ class _MyAppState extends State<MyApp> {
|
||||||
.sendMessage(castNamespace, message);
|
.sendMessage(castNamespace, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onCastVideo() {
|
||||||
|
final request = getMediaLoadRequestData();
|
||||||
|
castFramework.castContext.sessionManager.remoteMediaClient.load(request);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
|
|
@ -104,6 +110,10 @@ class _MyAppState extends State<MyApp> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Text('Received Message: $_message'),
|
Text('Received Message: $_message'),
|
||||||
|
ElevatedButton(
|
||||||
|
child: Text('Cast video'),
|
||||||
|
onPressed: _onCastVideo,
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
45
example/lib/media_load_request_data_helper.dart
Normal file
45
example/lib/media_load_request_data_helper.dart
Normal 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;
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue