Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions media_kit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ The following state(s) are available as events:
| `Stream<AudioParams>` | `audioParams` | Audio parameters of the currently playing media source e.g. sample rate, channels, etc. |
| `Stream<VideoParams>` | `videoParams` | Video parameters of the currently playing media source e.g. width, height, rotation etc. |
| `Stream<double?>` | `audioBitrate` | Audio bitrate of the currently playing media source. |
| `Stream<double?>` | `videoBitrate` | Video bitrate of the currently playing media source. |
| `Stream<AudioDevice>` | `audioDevice` | Currently selected audio device. |
| `Stream<List<AudioDevice>>` | `audioDevices` | Currently available audio devices. |
| `Stream<Track>` | `track` | Currently selected video, audio and subtitle track. |
Expand Down
25 changes: 19 additions & 6 deletions media_kit/lib/src/models/player_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import 'package:media_kit/src/models/audio_params.dart';
import 'package:media_kit/src/models/video_params.dart';
import 'package:media_kit/src/models/playlist_mode.dart';

const Object _undefined = Object();

/// {@template player_state}
///
/// PlayerState
Expand Down Expand Up @@ -68,6 +70,9 @@ class PlayerState {
/// Audio bitrate of the currently playing [Media].
final double? audioBitrate;

/// Video bitrate of the currently playing [Media].
final double? videoBitrate;

/// Currently selected [AudioDevice].
final AudioDevice audioDevice;

Expand Down Expand Up @@ -106,6 +111,7 @@ class PlayerState {
this.audioParams = const AudioParams(),
this.videoParams = const VideoParams(),
this.audioBitrate,
this.videoBitrate,
this.audioDevice = const AudioDevice('auto', ''),
this.audioDevices = const [AudioDevice('auto', '')],
this.track = const Track(),
Expand All @@ -130,13 +136,14 @@ class PlayerState {
PlaylistMode? playlistMode,
AudioParams? audioParams,
VideoParams? videoParams,
double? audioBitrate,
Object? audioBitrate = _undefined,
Object? videoBitrate = _undefined,
AudioDevice? audioDevice,
List<AudioDevice>? audioDevices,
Track? track,
Tracks? tracks,
int? width,
int? height,
Object? width = _undefined,
Object? height = _undefined,
List<String>? subtitle,
}) {
return PlayerState(
Expand All @@ -154,13 +161,18 @@ class PlayerState {
playlistMode: playlistMode ?? this.playlistMode,
audioParams: audioParams ?? this.audioParams,
videoParams: videoParams ?? this.videoParams,
audioBitrate: audioBitrate ?? this.audioBitrate,
audioBitrate: identical(audioBitrate, _undefined)
? this.audioBitrate
: audioBitrate as double?,
videoBitrate: identical(videoBitrate, _undefined)
? this.videoBitrate
: videoBitrate as double?,
audioDevice: audioDevice ?? this.audioDevice,
audioDevices: audioDevices ?? this.audioDevices,
track: track ?? this.track,
tracks: tracks ?? this.tracks,
width: width ?? this.width,
height: height ?? this.height,
width: identical(width, _undefined) ? this.width : width as int?,
height: identical(height, _undefined) ? this.height : height as int?,
subtitle: subtitle ?? this.subtitle,
);
}
Expand All @@ -182,6 +194,7 @@ class PlayerState {
'audioParams: $audioParams, '
'videoParams: $videoParams, '
'audioBitrate: $audioBitrate, '
'videoBitrate: $videoBitrate, '
'audioDevice: $audioDevice, '
'audioDevices: $audioDevices, '
'track: $track, '
Expand Down
4 changes: 4 additions & 0 deletions media_kit/lib/src/models/player_stream.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class PlayerStream {
/// Audio bitrate of the currently playing [Media].
final Stream<double?> audioBitrate;

/// Video bitrate of the currently playing [Media].
final Stream<double?> videoBitrate;

/// Currently selected [AudioDevice]s.
final Stream<AudioDevice> audioDevice;

Expand Down Expand Up @@ -113,6 +116,7 @@ class PlayerStream {
this.audioParams,
this.videoParams,
this.audioBitrate,
this.videoBitrate,
this.audioDevice,
this.audioDevices,
this.track,
Expand Down
21 changes: 21 additions & 0 deletions media_kit/lib/src/player/native/player/real.dart
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ class NativePlayer extends PlatformPlayer {
// if (!audioBitrateController.isClosed) {
// audioBitrateController.add(null);
// }
if (!videoBitrateController.isClosed) {
videoBitrateController.add(null);
}
// if (!audioDeviceController.isClosed) {
// audioDeviceController.add(AudioDevice.auto());
// }
Expand Down Expand Up @@ -1696,6 +1699,23 @@ class NativePlayer extends PlatformPlayer {
}
}
}
if (prop.ref.name.cast<Utf8>().toDartString() == 'video-bitrate' &&
prop.ref.format == generated.mpv_format.MPV_FORMAT_DOUBLE) {
if (state.playlist.index < state.playlist.medias.length &&
state.playlist.index >= 0) {
final bitrate = prop.ref.data.cast<Double>().value;
if (!videoBitrateController.isClosed &&
bitrate != state.videoBitrate) {
videoBitrateController.add(bitrate);
state = state.copyWith(videoBitrate: bitrate);
}
} else {
if (!videoBitrateController.isClosed) {
videoBitrateController.add(null);
state = state.copyWith(videoBitrate: null);
}
}
}
if (prop.ref.name.cast<Utf8>().toDartString() == 'track-list' &&
prop.ref.format == generated.mpv_format.MPV_FORMAT_NODE) {
final value = prop.ref.data.cast<generated.mpv_node>();
Expand Down Expand Up @@ -2454,6 +2474,7 @@ class NativePlayer extends PlatformPlayer {
'cache-buffering-state': generated.mpv_format.MPV_FORMAT_DOUBLE,
'audio-params': generated.mpv_format.MPV_FORMAT_NODE,
'audio-bitrate': generated.mpv_format.MPV_FORMAT_DOUBLE,
'video-bitrate': generated.mpv_format.MPV_FORMAT_DOUBLE,
'audio-device': generated.mpv_format.MPV_FORMAT_NODE,
'audio-device-list': generated.mpv_format.MPV_FORMAT_NODE,
'video-params': generated.mpv_format.MPV_FORMAT_NODE,
Expand Down
8 changes: 8 additions & 0 deletions media_kit/lib/src/player/platform_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ abstract class PlatformPlayer {
audioBitrateController.stream.distinct(
(previous, current) => previous == current,
),
videoBitrateController.stream.distinct(
(previous, current) => previous == current,
),
audioDeviceController.stream.distinct(
(previous, current) => previous == current,
),
Expand Down Expand Up @@ -133,6 +136,7 @@ abstract class PlatformPlayer {
audioParamsController.close(),
videoParamsController.close(),
audioBitrateController.close(),
videoBitrateController.close(),
audioDeviceController.close(),
audioDevicesController.close(),
trackController.close(),
Expand Down Expand Up @@ -371,6 +375,10 @@ abstract class PlatformPlayer {
final StreamController<double?> audioBitrateController =
StreamController<double?>.broadcast();

@protected
final StreamController<double?> videoBitrateController =
StreamController<double?>.broadcast();

@protected
final StreamController<AudioDevice> audioDeviceController =
StreamController<AudioDevice>.broadcast();
Expand Down
3 changes: 3 additions & 0 deletions media_kit/lib/src/player/web/player/real.dart
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,9 @@ class WebPlayer extends PlatformPlayer {
if (!audioBitrateController.isClosed) {
audioBitrateController.add(null);
}
if (!videoBitrateController.isClosed) {
videoBitrateController.add(null);
}
// if (!audioDeviceController.isClosed) {
// audioDeviceController.add(AudioDevice.auto());
// }
Expand Down
4 changes: 4 additions & 0 deletions media_kit/test/src/models/media/player_state_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ void main() {
state.audioBitrate,
isNull,
);
expect(
state.videoBitrate,
isNull,
);
expect(state.videoParams.pixelformat, isNull);
expect(state.videoParams.hwPixelformat, isNull);
expect(state.videoParams.w, isNull);
Expand Down
1 change: 1 addition & 0 deletions media_kit/test/src/player/player_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2792,6 +2792,7 @@ void main() {
expect(player.state.audioParams, equals(const AudioParams()));
expect(player.state.videoParams, equals(const VideoParams()));
expect(player.state.audioBitrate, equals(null));
expect(player.state.videoBitrate, equals(null));
expect(player.state.track, equals(const Track()));
expect(player.state.tracks, equals(const Tracks()));
expect(player.state.width, equals(null));
Expand Down
16 changes: 16 additions & 0 deletions media_kit_test/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'tests/08.screenshot.dart';
import 'tests/09.seamless.dart';
import 'tests/10.programmatic_fullscreen.dart';
import 'tests/11.video_view_parameters.dart';
import 'tests/12.video_bitrate.dart';

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
Expand Down Expand Up @@ -246,6 +247,21 @@ class PrimaryScreen extends StatelessWidget {
);
},
),
ListTile(
title: const Text(
'video_bitrate.dart',
style: TextStyle(fontSize: 14.0),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const VideoBitrateScreen(),
),
);
},
),
],
),
);
Expand Down
Loading
Loading