Skip to content

Commit

Permalink
Merge pull request #185 from JulienDev/feat/add-player-extensions
Browse files Browse the repository at this point in the history
feat: add player extensions
  • Loading branch information
wang-bin authored Nov 26, 2024
2 parents 9c935f6 + 6bcc281 commit b8ff988
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
23 changes: 23 additions & 0 deletions lib/src/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import 'dart:typed_data';
import 'package:video_player/video_player.dart';
import 'package:video_player_platform_interface/video_player_platform_interface.dart';

import 'media_info.dart'
if (dart.library.js_interop) 'media_info_dummy.dart'
if (dart.library.html) 'media_info_dummy.dart';
import 'video_player_mdk.dart'
if (dart.library.js_interop) 'video_player_dummy.dart'
if (dart.library.html) 'video_player_dummy.dart';
Expand All @@ -28,6 +31,11 @@ extension FVPControllerExtensions on VideoPlayerController {
return _platform.isLive(textureId);
}

/// Get current media info.
MediaInfo? getMediaInfo() {
return _platform.getMediaInfo(textureId);
}

/// set additional properties
/// https://github.com/wang-bin/mdk-sdk/wiki/Player-APIs#void-setpropertyconst-stdstring-key-const-stdstring-value
void setProperty(String name, String value) {
Expand Down Expand Up @@ -118,20 +126,35 @@ extension FVPControllerExtensions on VideoPlayerController {
_platform.setAudioTracks(textureId, value);
}

/// Get active audio tracks.
List<int>? getActiveAudioTracks() {
return _platform.getActiveAudioTracks(textureId);
}

/// Set active video tracks. Other tracks will be disabled.
/// The tracks can be from data source from [VideoPlayerController] constructor, or an external video data source via [setExternalVideo]
/// https://github.com/wang-bin/mdk-sdk/wiki/Player-APIs#void-setactivetracksmediatype-type-const-stdsetint-tracks
void setVideoTracks(List<int> value) {
_platform.setVideoTracks(textureId, value);
}

/// Get active video tracks.
List<int>? getActiveVideoTracks() {
return _platform.getActiveVideoTracks(textureId);
}

/// Set active subtitle tracks. Other tracks will be disabled.
/// The tracks can be from data source from [VideoPlayerController] constructor, or an external subtitle data source via [setExternalSubtitle]
/// https://github.com/wang-bin/mdk-sdk/wiki/Player-APIs#void-setactivetracksmediatype-type-const-stdsetint-tracks
void setSubtitleTracks(List<int> value) {
_platform.setSubtitleTracks(textureId, value);
}

/// Get active subtitle tracks.
List<int>? getActiveSubtitleTracks() {
return _platform.getActiveSubtitleTracks(textureId);
}

/// set an external audio data source
/// https://github.com/wang-bin/mdk-sdk/wiki/Player-APIs#void-setmediaconst-char-url-mediatype-type
void setExternalAudio(String uri) {
Expand Down
4 changes: 4 additions & 0 deletions lib/src/media_info_dummy.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// A dummy class for web
class MediaInfo {

}
17 changes: 17 additions & 0 deletions lib/src/video_player_dummy.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:typed_data';

import 'media_info_dummy.dart';

/// A dummy class for web
class MdkVideoPlayerPlatform {
static void registerVideoPlayerPlatformsWith({dynamic options}) {}
Expand All @@ -9,6 +11,8 @@ class MdkVideoPlayerPlatform {
return false;
}

MediaInfo? getMediaInfo(int textureId) { return null; }

void setProperty(int textureId, String name, String value) {}

void setAudioDecoders(int textureId, List<String> value) {}
Expand Down Expand Up @@ -37,12 +41,25 @@ class MdkVideoPlayerPlatform {
void setHue(int textureId, double value) {}

void setSaturation(int textureId, double value) {}

void setAudioTracks(int textureId, List<int> value) {}

List<int>? getActiveAudioTracks(int textureId) {
return null;
}

void setVideoTracks(int textureId, List<int> value) {}

List<int>? getActiveVideoTracks(int textureId) {
return null;
}

void setSubtitleTracks(int textureId, List<int> value) {}

List<int>? getActiveSubtitleTracks(int textureId) {
return null;
}

void setExternalAudio(int textureId, String uri) {}

void setExternalVideo(int textureId, String uri) {}
Expand Down
21 changes: 18 additions & 3 deletions lib/src/video_player_mdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import 'package:video_player_platform_interface/video_player_platform_interface.
import 'package:logging/logging.dart';
import 'fvp_platform_interface.dart';
import 'extensions.dart';
import 'media_info.dart';

import '../mdk.dart' as mdk;


final _log = Logger('fvp');

class MdkVideoPlayer extends mdk.Player {
Expand Down Expand Up @@ -349,9 +351,10 @@ class MdkVideoPlayerPlatform extends VideoPlayerPlatform {
return _players[textureId]?.isLive ?? false;
}

//MediaInfo getMediaInfo() {
//
//}
MediaInfo? getMediaInfo(int textureId) {
return _players[textureId]?.mediaInfo;
}

void setProperty(int textureId, String name, String value) {
_players[textureId]?.setProperty(name, value);
}
Expand Down Expand Up @@ -422,14 +425,26 @@ class MdkVideoPlayerPlatform extends VideoPlayerPlatform {
_players[textureId]?.activeAudioTracks = value;
}

List<int>? getActiveAudioTracks(int textureId) {
return _players[textureId]?.activeAudioTracks;
}

void setVideoTracks(int textureId, List<int> value) {
_players[textureId]?.activeVideoTracks = value;
}

List<int>? getActiveVideoTracks(int textureId) {
return _players[textureId]?.activeVideoTracks;
}

void setSubtitleTracks(int textureId, List<int> value) {
_players[textureId]?.activeSubtitleTracks = value;
}

List<int>? getActiveSubtitleTracks(int textureId) {
return _players[textureId]?.activeSubtitleTracks;
}

// external track. can select external tracks via setAudioTracks()
void setExternalAudio(int textureId, String uri) {
_players[textureId]?.setMedia(uri, mdk.MediaType.audio);
Expand Down

0 comments on commit b8ff988

Please sign in to comment.