Skip to content

Commit

Permalink
Add new api getStreamingProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaowei-guan committed Feb 28, 2024
1 parent 0bbced7 commit 179f082
Show file tree
Hide file tree
Showing 11 changed files with 438 additions and 11 deletions.
101 changes: 96 additions & 5 deletions packages/video_player_avplay/lib/src/messages.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,58 @@ class DurationMessage {
}
}

class StreamingPropertyMessage {
StreamingPropertyMessage({
required this.playerId,
required this.streamingProperty,
});

int playerId;

String streamingProperty;

Object encode() {
return <Object?>[
playerId,
streamingProperty,
];
}

static StreamingPropertyMessage decode(Object result) {
result as List<Object?>;
return StreamingPropertyMessage(
playerId: result[0]! as int,
streamingProperty: result[1]! as String,
);
}
}

class StreamingPropertyTypeMessage {
StreamingPropertyTypeMessage({
required this.playerId,
required this.streamingPropertyType,
});

int playerId;

String streamingPropertyType;

Object encode() {
return <Object?>[
playerId,
streamingPropertyType,
];
}

static StreamingPropertyTypeMessage decode(Object result) {
result as List<Object?>;
return StreamingPropertyTypeMessage(
playerId: result[0]! as int,
streamingPropertyType: result[1]! as String,
);
}
}

class _VideoPlayerAvplayApiCodec extends StandardMessageCodec {
const _VideoPlayerAvplayApiCodec();
@override
Expand Down Expand Up @@ -395,15 +447,21 @@ class _VideoPlayerAvplayApiCodec extends StandardMessageCodec {
} else if (value is SelectedTracksMessage) {
buffer.putUint8(136);
writeValue(buffer, value.encode());
} else if (value is TrackMessage) {
} else if (value is StreamingPropertyMessage) {
buffer.putUint8(137);
writeValue(buffer, value.encode());
} else if (value is TrackTypeMessage) {
} else if (value is StreamingPropertyTypeMessage) {
buffer.putUint8(138);
writeValue(buffer, value.encode());
} else if (value is VolumeMessage) {
} else if (value is TrackMessage) {
buffer.putUint8(139);
writeValue(buffer, value.encode());
} else if (value is TrackTypeMessage) {
buffer.putUint8(140);
writeValue(buffer, value.encode());
} else if (value is VolumeMessage) {
buffer.putUint8(141);
writeValue(buffer, value.encode());
} else {
super.writeValue(buffer, value);
}
Expand Down Expand Up @@ -431,10 +489,14 @@ class _VideoPlayerAvplayApiCodec extends StandardMessageCodec {
case 136:
return SelectedTracksMessage.decode(readValue(buffer)!);
case 137:
return TrackMessage.decode(readValue(buffer)!);
return StreamingPropertyMessage.decode(readValue(buffer)!);
case 138:
return TrackTypeMessage.decode(readValue(buffer)!);
return StreamingPropertyTypeMessage.decode(readValue(buffer)!);
case 139:
return TrackMessage.decode(readValue(buffer)!);
case 140:
return TrackTypeMessage.decode(readValue(buffer)!);
case 141:
return VolumeMessage.decode(readValue(buffer)!);
default:
return super.readValueOfType(type, buffer);
Expand Down Expand Up @@ -876,4 +938,33 @@ class VideoPlayerAvplayApi {
return;
}
}

Future<StreamingPropertyMessage> getStreamingProperty(
StreamingPropertyTypeMessage arg_msg) async {
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'dev.flutter.pigeon.video_player_avplay.VideoPlayerAvplayApi.getStreamingProperty',
codec,
binaryMessenger: _binaryMessenger);
final List<Object?>? replyList =
await channel.send(<Object?>[arg_msg]) as List<Object?>?;
if (replyList == null) {
throw PlatformException(
code: 'channel-error',
message: 'Unable to establish connection on channel.',
);
} else if (replyList.length > 1) {
throw PlatformException(
code: replyList[0]! as String,
message: replyList[1] as String?,
details: replyList[2],
);
} else if (replyList[0] == null) {
throw PlatformException(
code: 'null-error',
message: 'Host platform returned null value for non-null return value.',
);
} else {
return (replyList[0] as StreamingPropertyMessage?)!;
}
}
}
27 changes: 27 additions & 0 deletions packages/video_player_avplay/lib/src/video_player_tizen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ class VideoPlayerTizen extends VideoPlayerPlatform {
return Duration(milliseconds: response.position);
}

@override
Future<String> getStreamingProperty(
int playerId, StreamingPropertyType type) async {
final StreamingPropertyMessage streamingPropertyMessage =
await _api.getStreamingProperty(StreamingPropertyTypeMessage(
playerId: playerId, streamingPropertyType: _streamingPropertyType[type]!));
return streamingPropertyMessage.streamingProperty;
}

@override
Stream<VideoEvent> videoEventsFor(int playerId) {
return _eventChannelFor(playerId)
Expand Down Expand Up @@ -286,4 +295,22 @@ class VideoPlayerTizen extends VideoPlayerPlatform {
2: AudioTrackChannelType.stereo,
3: AudioTrackChannelType.surround,
};

static const Map<StreamingPropertyType, String> _streamingPropertyType =
<StreamingPropertyType, String>{
StreamingPropertyType.ADAPTIVE_INFO: 'ADAPTIVE_INFO',
StreamingPropertyType.AVAILABLE_BITRATE: 'AVAILABLE_BITRATE',
StreamingPropertyType.COOKIE: 'COOKIE',
StreamingPropertyType.CURRENT_BANDWIDTH: 'CURRENT_BANDWIDTH',
StreamingPropertyType.GET_LIVE_DURATION: 'GET_LIVE_DURATION',
StreamingPropertyType.IN_APP_MULTIVIEW: 'IN_APP_MULTIVIEW',
StreamingPropertyType.IS_LIVE: 'IS_LIVE',
StreamingPropertyType.LISTEN_SPARSE_TRACK: 'LISTEN_SPARSE_TRACK',
StreamingPropertyType.PORTRAIT_MODE: 'PORTRAIT_MODE',
StreamingPropertyType.PREBUFFER_MODE: 'PREBUFFER_MODE',
StreamingPropertyType.SET_MIXEDFRAME: 'SET_MIXEDFRAME',
StreamingPropertyType.SET_MODE_4K: 'SET_MODE_4K',
StreamingPropertyType.USER_AGENT: 'USER_AGENT',
StreamingPropertyType.USE_VIDEOMIXER: 'USE_VIDEOMIXER',
};
}
8 changes: 8 additions & 0 deletions packages/video_player_avplay/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,14 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
await _applyVolume();
}

/// Retrieves a specific property value obtained by the streaming engine (Smooth Streaming, HLS, DASH, or Widevine).
Future<String> getStreamingProperty(StreamingPropertyType type) async {
if (_isDisposedOrNotInitialized) {
return '';
}
return _videoPlayerPlatform.getStreamingProperty(_playerId, type);
}

/// Sets the playback speed of [this].
///
/// [speed] indicates a speed value with different platforms accepting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ abstract class VideoPlayerPlatform extends PlatformInterface {
throw UnimplementedError('getDuration() has not been implemented.');
}

/// Retrieves a specific property value obtained by the streaming engine (Smooth Streaming, HLS, DASH, or Widevine).
Future<String> getStreamingProperty(
int playerId, StreamingPropertyType type) {
throw UnimplementedError(
'getStreamingProperty() has not been implemented.');
}

/// Returns a widget displaying the video with a given playerId.
Widget buildView(int playerId) {
throw UnimplementedError('buildView() has not been implemented.');
Expand Down Expand Up @@ -253,6 +260,73 @@ enum VideoFormat {
other,
}

/// The file format of the given video.
enum StreamingPropertyType {
/// HTTP request cookie used to establish the session with the HTTP server.
COOKIE,

/// HTTP user agent, used in the HTTP request header.
USER_AGENT,

/// Property to initiate prebuffering mode. The second parameter indicates start-time for prebuffered content, in milliseconds.
PREBUFFER_MODE,

/// Sets a custom streaming URL with various streaming parameters, such as "BITRATES", "STARTBITRATE", or "SKIPBITRATE".
/// String containing custom attributes for adaptive streaming playback.
/// "STARTBITRATE=" Valid values are "LOWEST", "HIGHEST", and "AVERAGE". You can also define a specific bandwidth for the start of playback.
/// "BITRATES=" Use '~' to define a bandwidth range (5000 ~ 20000). You can also define a specific bandwidth for playback.
/// "SKIPBITRATE=" Defines the bandwidth to use after a skip operation.
/// "STARTFRAGMENT=" For live content playback, defines the start fragment number.
/// "FIXED_MAX_RESOLUTION=max_widthXmax_height". Only if the given media URI such as mpd in MPEG-DASH or m3u8 in HLS through open()
/// method doesn't describe entire required video resolutions,application should use this attribute to complete the resolution information for the player.
ADAPTIVE_INFO,

/// Forces the player to use the 4K UHD decoder. Its parameter can be the string "TRUE" or "FALSE".
/// In the case of adaptive streaming which requires stream-change for different video resolution during the playback,
/// Only if the given media URI such as mpd in MPEG-DASH or m3u8 in HLS through open() method doesn't describe entire required video resolutions,
/// pass TRUE with this property in IDLE state.
SET_MODE_4K,

/// For the Smooth Streaming case, configures the player to listen for a "Sparse name" configured through "propertyParam" . The sparse track name is a string.
LISTEN_SPARSE_TRACK,

/// Whether the stream is LIVE or VOD. Applicable to all streaming types.
IS_LIVE,

/// String listing the available bit-rates for the currently-playing stream.
AVAILABLE_BITRATE,

/// String describing the duration of live content.
GET_LIVE_DURATION,

/// String describing the current streaming bandwidth.
CURRENT_BANDWIDTH,

/// Property used for enabling/initializing video mixer feature on B2B product only. It should be set before
/// setting SET_MIXEDFRAME property on the player.
USE_VIDEOMIXER,

/// : Property to set the position of mixed frame. setDisplayRect with required position on corresponding
/// player instance to be called before setting this property.
SET_MIXEDFRAME,

/// Property to force the playback the video in potrait mode on B2B proudct only.
PORTRAIT_MODE,

/// Property to select the Scaler type, By Default MAIN Scaler selected.
IN_APP_MULTIVIEW,
}

/// Event emitted from the platform implementation.
@immutable
class VideoEvent {
Expand Down
14 changes: 14 additions & 0 deletions packages/video_player_avplay/pigeons/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ class DurationMessage {
List<int?>? durationRange;
}

class StreamingPropertyMessage {
StreamingPropertyMessage(this.playerId, this.streamingProperty);
int playerId;
String streamingProperty;
}

class StreamingPropertyTypeMessage {
StreamingPropertyTypeMessage(this.playerId, this.streamingPropertyType);
int playerId;
String streamingPropertyType;
}

@HostApi()
abstract class VideoPlayerAvplayApi {
void initialize();
Expand All @@ -109,4 +121,6 @@ abstract class VideoPlayerAvplayApi {
void pause(PlayerMessage msg);
void setMixWithOthers(MixWithOthersMessage msg);
void setDisplayGeometry(GeometryMessage msg);
StreamingPropertyMessage getStreamingProperty(
StreamingPropertyTypeMessage msg);
}
Loading

0 comments on commit 179f082

Please sign in to comment.