LCOV - code coverage report
Current view: top level - models/ios - ios_media_information.dart Coverage Total Hit
Test: lcov_cleaned.info Lines: 42.9 % 49 21
Test Date: 2025-06-20 10:50:47 Functions: - 0 0

            Line data    Source code
       1              : import 'package:flutter_chrome_cast/lib.dart';
       2              : import 'package:flutter_chrome_cast/models/ios/ios_media_track.dart';
       3              : 
       4              : import 'metadata/generic.dart';
       5              : import 'metadata/movie.dart';
       6              : import 'metadata/music.dart';
       7              : import 'metadata/photo.dart';
       8              : import 'metadata/tv_show.dart';
       9              : 
      10              : /// iOS-specific implementation of [GoogleCastMediaInformation].
      11              : ///
      12              : /// This class represents the media information required to load and control media playback
      13              : /// on Google Cast devices from iOS. It extends the cross-platform [GoogleCastMediaInformation]
      14              : /// and provides a factory for constructing from a platform channel map.
      15              : ///
      16              : /// Typical usage involves creating an instance with all required media details, or using
      17              : /// [GoogleCastMediaInformationIOS.fromMap] to parse data received from the native iOS layer.
      18              : ///
      19              : /// See also:
      20              : /// - [GoogleCastMediaInformation] for the base class and common fields
      21              : /// - [GoogleCastRemoteMediaClient] for loading and controlling media
      22              : /// - [GoogleCastMediaTrack] for track details
      23              : /// - [GoogleCastMediaMetadataType] for supported metadata types
      24              : class GoogleCastMediaInformationIOS extends GoogleCastMediaInformation {
      25              :   /// Creates a new [GoogleCastMediaInformationIOS] instance.
      26              :   ///
      27              :   /// All parameters are forwarded to the base [GoogleCastMediaInformation].
      28            1 :   GoogleCastMediaInformationIOS({
      29              :     required super.contentId,
      30              :     required super.streamType,
      31              :     required super.contentType,
      32              :     super.atvEntity,
      33              :     super.breakClips,
      34              :     super.breaks,
      35              :     super.contentUrl,
      36              :     super.customData,
      37              :     super.duration,
      38              :     super.entity,
      39              :     super.hlsSegmentFormat,
      40              :     super.hlsVideoSegmentFormat,
      41              :     super.metadata,
      42              :     super.startAbsoluteTime,
      43              :     super.textTrackStyle,
      44              :     super.tracks,
      45              :     super.userActionStates,
      46              :     super.vmapAdsRequest,
      47              :   });
      48              : 
      49              :   /// Creates a [GoogleCastMediaInformationIOS] from a [Map] received from the platform channel.
      50              :   ///
      51              :   /// The [map] parameter must contain the expected keys and value types as sent from iOS.
      52            1 :   factory GoogleCastMediaInformationIOS.fromMap(Map<String, dynamic> map) {
      53            1 :     return GoogleCastMediaInformationIOS(
      54            1 :       atvEntity: map['atvEntity'],
      55            1 :       breakClips: map['breakClips'] != null
      56            0 :           ? List<CastBreakClips>.from(
      57            0 :               map['breakClips']?.map((x) => CastBreakClips.fromMap(x)))
      58              :           : null,
      59            1 :       contentId: map['contentID'] ?? '',
      60            2 :       streamType: CastMediaStreamType.values[map['streamType']],
      61            1 :       contentType: map['contentType'] ?? '',
      62            1 :       metadata: map['metadata'] != null
      63            0 :           ? _getCastMediaMetadata(Map.from(map['metadata']))
      64              :           : null,
      65            1 :       duration: map['duration'] != null
      66            0 :           ? Duration(seconds: map['duration']?.round() ?? 0)
      67              :           : null,
      68            3 :       customData: Map<String, dynamic>.from(map['customData'] ?? {}),
      69            1 :       breaks: map['breaks'] != null
      70            0 :           ? List<CastBreak>.from(
      71            0 :               map['breaks']?.map((x) => CastBreak.fromMap(x)))
      72              :           : null,
      73            2 :       contentUrl: Uri.tryParse(map['contentURL'] ?? ''),
      74            1 :       entity: map['entity'],
      75            1 :       hlsSegmentFormat: map['hlsSegmentFormat'] != null
      76            0 :           ? CastHlsSegmentFormat.fromMap(map['hlsSegmentFormat'])
      77              :           : null,
      78            1 :       hlsVideoSegmentFormat: map['hlsVideoSegmentFormat'] != null
      79            0 :           ? HlsVideoSegmentFormat.fromMap(map['hlsVideoSegmentFormat'])
      80              :           : null,
      81            1 :       startAbsoluteTime: map['startAbsoluteTime'] != null
      82            0 :           ? DateTime.fromMillisecondsSinceEpoch(map['startAbsoluteTime'])
      83              :           : null,
      84            1 :       textTrackStyle: map['textTrackStyle'] != null
      85            0 :           ? TextTrackStyle.fromMap(map['textTrackStyle'])
      86              :           : null,
      87            1 :       tracks: map['tracks'] != null
      88            0 :           ? List<GoogleCastMediaTrack>.from(
      89            0 :               map['tracks']?.map(
      90            0 :                 (x) => IosMediaTrack.fromMap(x),
      91              :               ),
      92              :             )
      93              :           : null,
      94            1 :       userActionStates: map['userActionStates'] != null
      95            0 :           ? List<UserActionState>.from(
      96            0 :               map['userActionStates']?.map((x) => UserActionState.fromMap(x)))
      97              :           : null,
      98            1 :       vmapAdsRequest: map['vmapAdsRequest'] != null
      99            0 :           ? VastAdsRequest.fromMap(map['vmapAdsRequest'])
     100              :           : null,
     101              :     );
     102              :   }
     103              : }
     104              : 
     105            0 : GoogleCastMediaMetadata? _getCastMediaMetadata(Map<String, dynamic> map) {
     106            0 :   final type = GoogleCastMediaMetadataType.values[map['type']];
     107            0 :   if (type == GoogleCastMediaMetadataType.genericMediaMetadata) {
     108            0 :     return GoogleCastGenericMediaMetadataIOS.fromMap(map);
     109            0 :   } else if (type == GoogleCastMediaMetadataType.movieMediaMetadata) {
     110            0 :     return GoogleCastMovieMediaMetadataIOS.fromMap(map);
     111            0 :   } else if (type == GoogleCastMediaMetadataType.tvShowMediaMetadata) {
     112            0 :     return GoogleCastTvShowMediaMetadataIOS.fromMap(map);
     113            0 :   } else if (type == GoogleCastMediaMetadataType.musicTrackMediaMetadata) {
     114            0 :     return GoogleCastMusicMediaMetadataIOS.fromMap(map);
     115            0 :   } else if (type == GoogleCastMediaMetadataType.photoMediaMetadata) {
     116            0 :     return GooglCastPhotoMediaMetadataIOS.fromMap(map);
     117              :   } else {
     118              :     return null;
     119              :   }
     120              : }
        

Generated by: LCOV version 2.3.1-1