Skip to content

Commit

Permalink
Create dash plusplayer if videoFormat is dash (#1)
Browse files Browse the repository at this point in the history
* Create dash plusplayer if videoFormat is dash

* Use reference
  • Loading branch information
hyue7 authored Sep 27, 2023
1 parent e1a7e5b commit 656262a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
6 changes: 5 additions & 1 deletion packages/video_player_avplayer/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
import 'package:video_player_avplayer/video_player.dart';
import 'package:video_player_avplayer/video_player_platform_interface.dart';

void main() {
runApp(
Expand Down Expand Up @@ -129,7 +130,9 @@ class _DashRomoteVideoState extends State<_DashRomoteVideo> {
void initState() {
super.initState();
_controller = VideoPlayerController.network(
'https://dash.akamaized.net/dash264/TestCasesUHD/2b/11/MultiRate.mpd');
'https://dash.akamaized.net/dash264/TestCasesUHD/2b/11/MultiRate.mpd',
formatHint: VideoFormat.dash,
);

_controller.addListener(() {
if (_controller.value.hasError) {
Expand Down Expand Up @@ -259,6 +262,7 @@ class _DrmRemoteVideoState extends State<_DrmRemoteVideo> {
return response.bodyBytes;
},
),
formatHint: VideoFormat.dash,
);

_controller.addListener(() {
Expand Down
14 changes: 11 additions & 3 deletions packages/video_player_avplayer/tizen/src/plus_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,24 @@

#include "log.h"

PlusPlayer::PlusPlayer(flutter::BinaryMessenger *messenger, void *native_window)
: VideoPlayer(messenger), native_window_(native_window) {}
PlusPlayer::PlusPlayer(flutter::BinaryMessenger *messenger, void *native_window,
std::string &video_format)
: VideoPlayer(messenger),
native_window_(native_window),
video_format_(video_format) {}

PlusPlayer::~PlusPlayer() { Dispose(); }

int64_t PlusPlayer::Create(const std::string &uri, int drm_type,
const std::string &license_server_url,
bool is_prebuffer_mode) {
LOG_INFO("[PlusPlayer] Create player.");
player_ = plusplayer::PlusPlayer::Create();
if (!video_format_.compare("dash")) {
player_ = plusplayer::PlusPlayer::Create(plusplayer::PlayerType::kDASH);
} else {
player_ = plusplayer::PlusPlayer::Create();
}

if (!player_) {
LOG_ERROR("[PlusPlayer] Fail to create player.");
return -1;
Expand Down
4 changes: 3 additions & 1 deletion packages/video_player_avplayer/tizen/src/plus_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

class PlusPlayer : public VideoPlayer, public plusplayer::EventListener {
public:
explicit PlusPlayer(flutter::BinaryMessenger *messenger, void *native_window);
explicit PlusPlayer(flutter::BinaryMessenger *messenger, void *native_window,
std::string &video_format);
~PlusPlayer();

int64_t Create(const std::string &uri, int drm_type,
Expand Down Expand Up @@ -82,6 +83,7 @@ class PlusPlayer : public VideoPlayer, public plusplayer::EventListener {
std::unique_ptr<plusplayer::PlusPlayer> player_;
void *native_window_;
std::unique_ptr<DrmManager> drm_manager_;
std::string video_format_;
bool is_buffering_ = false;
bool is_prebuffer_mode_ = false;
SeekCompletedCallback on_seek_completed_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ ErrorOr<PlayerMessage> VideoPlayerTizenPlugin::Create(
int32_t drm_type = 0; // DRM_TYPE_NONE
std::string license_server_url;
bool prebuffer_mode;
std::string format;

if (msg.asset() && !msg.asset()->empty()) {
char *res_path = app_get_resource_path();
Expand All @@ -130,6 +131,9 @@ ErrorOr<PlayerMessage> VideoPlayerTizenPlugin::Create(
}
} else if (msg.uri() && !msg.uri()->empty()) {
uri = *msg.uri();
if (msg.format_hint() && !msg.format_hint()->empty()) {
format = *msg.format_hint();
}

const flutter::EncodableMap *drm_configs = msg.drm_configs();
if (drm_configs) {
Expand Down Expand Up @@ -164,7 +168,7 @@ ErrorOr<PlayerMessage> VideoPlayerTizenPlugin::Create(
int64_t player_id = 0;
if (uri.substr(0, 4) == "http") {
auto player = std::make_unique<PlusPlayer>(plugin_registrar_->messenger(),
native_window);
native_window, format);
player_id =
player->Create(uri, drm_type, license_server_url, prebuffer_mode);
players_[player_id] = std::move(player);
Expand Down

0 comments on commit 656262a

Please sign in to comment.