Line data Source code
1 : import 'package:flutter_chrome_cast/lib.dart';
2 :
3 : /// Android-specific extension of [GoogleCastMediaInformation].
4 : class GoogleCastMediaInformationAndroid extends GoogleCastMediaInformation {
5 : /// Creates a new [GoogleCastMediaInformationAndroid] instance.
6 1 : GoogleCastMediaInformationAndroid({
7 : required super.contentId,
8 : required super.streamType,
9 : required super.contentType,
10 : super.atvEntity,
11 : super.breakClips,
12 : super.breaks,
13 : super.contentUrl,
14 : super.customData,
15 : super.duration,
16 : super.entity,
17 : super.hlsSegmentFormat,
18 : super.hlsVideoSegmentFormat,
19 : super.metadata,
20 : super.startAbsoluteTime,
21 : super.textTrackStyle,
22 : super.tracks,
23 : super.userActionStates,
24 : super.vmapAdsRequest,
25 : });
26 :
27 : /// Creates a [GoogleCastMediaInformationAndroid] from a map.
28 1 : factory GoogleCastMediaInformationAndroid.fromMap(Map<String, dynamic> map) {
29 1 : return GoogleCastMediaInformationAndroid(
30 1 : atvEntity: map['atvEntity'],
31 1 : breakClips: map['breakClips'] != null
32 0 : ? List<CastBreakClips>.from(
33 0 : map['breakClips']?.map((x) => CastBreakClips.fromMap(x)))
34 : : null,
35 1 : contentId: map['contentId'] ?? '',
36 2 : streamType: GoogleCastAndroidStreamType.fromMap(map['streamType']),
37 1 : contentType: map['contentType'] ?? '',
38 1 : metadata: map['metadata'] != null
39 0 : ? _getCastMediaMetadata(Map.from(map['metadata']))
40 : : null,
41 1 : duration: map['duration'] != null
42 0 : ? Duration(seconds: map['duration'].round())
43 : : null,
44 3 : customData: Map<String, dynamic>.from(map['customData'] ?? {}),
45 1 : breaks: map['breaks'] != null
46 0 : ? List<CastBreak>.from(
47 0 : map['breaks']?.map((x) => CastBreak.fromMap(x)))
48 : : null,
49 2 : contentUrl: Uri.tryParse(map['contentUrl'] ?? ''),
50 1 : entity: map['entity'],
51 1 : hlsSegmentFormat: map['hlsSegmentFormat'] != null
52 0 : ? CastHlsSegmentFormat.fromMap(map['hlsSegmentFormat'])
53 : : null,
54 1 : hlsVideoSegmentFormat: map['hlsVideoSegmentFormat'] != null
55 0 : ? HlsVideoSegmentFormat.fromMap(map['hlsVideoSegmentFormat'])
56 : : null,
57 1 : startAbsoluteTime: map['startAbsoluteTime'] != null
58 0 : ? DateTime.fromMillisecondsSinceEpoch(map['startAbsoluteTime'])
59 : : null,
60 1 : textTrackStyle: map['textTrackStyle'] != null
61 0 : ? TextTrackStyle.fromMap(map['textTrackStyle'])
62 : : null,
63 1 : tracks: map['tracks'] != null
64 0 : ? List<GoogleCastMediaTrack>.from(map['tracks']?.map((x) =>
65 0 : GoogleCastMediaTrack.fromMap(Map<String, dynamic>.from(x))))
66 : : null,
67 1 : userActionStates: map['userActionStates'] != null
68 0 : ? List<UserActionState>.from(
69 0 : map['userActionStates']?.map((x) => UserActionState.fromMap(x)))
70 : : null,
71 1 : vmapAdsRequest: map['vmapAdsRequest'] != null
72 0 : ? VastAdsRequest.fromMap(map['vmapAdsRequest'])
73 : : null,
74 : );
75 : }
76 : }
77 :
78 0 : GoogleCastMediaMetadata? _getCastMediaMetadata(Map<String, dynamic> map) {
79 0 : final type = map['metadataType'] as int;
80 : GoogleCastMediaMetadata? metadata;
81 : switch (type) {
82 : //Generic
83 0 : case 0:
84 0 : metadata = GoogleCastGenericMediaMetadataAndroid.fromMap(map);
85 : break;
86 : //MOVIE
87 0 : case 1:
88 0 : metadata = GoogleCastMovieMediaMetadataAndroid.fromMap(map);
89 : break;
90 : //TV SHOW
91 0 : case 2:
92 0 : metadata = GoogleCastTvShowMediaMetadataAndroid.fromMap(map);
93 : break;
94 : //Music
95 0 : case 3:
96 0 : metadata = GoogleCastMusicMediaMetadataAndroid.fromMap(map);
97 : break;
98 : //Photo
99 0 : case 4:
100 0 : metadata = GooglCastPhotoMediaMetadataAndroid.fromMap(map);
101 : break;
102 : default:
103 : }
104 : return metadata;
105 : }
|