Skip to content

[video_player_avplay] Add error event #830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions packages/video_player_avplay/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.18

* Add player error event.

## 0.5.17

* Update readme.
Expand Down
2 changes: 1 addition & 1 deletion packages/video_player_avplay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ To use this package, add `video_player_avplay` as a dependency in your `pubspec.

```yaml
dependencies:
video_player_avplay: ^0.5.17
video_player_avplay: ^0.5.18
```

Then you can import `video_player_avplay` in your Dart code:
Expand Down
5 changes: 5 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 @@ -340,6 +340,11 @@ class VideoPlayerTizen extends VideoPlayerPlatform {
eventType: VideoEventType.isPlayingStateUpdate,
isPlaying: map['isPlaying']! as bool,
);
case 'error':
return VideoEvent(
eventType: VideoEventType.error,
playerError: PlayerError.values[map['errorCode']! as int],
);
default:
return VideoEvent(eventType: VideoEventType.unknown);
}
Expand Down
16 changes: 13 additions & 3 deletions packages/video_player_avplay/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class VideoPlayerValue {
this.playbackSpeed = 1.0,
this.errorDescription,
this.isCompleted = false,
this.playerError = PlayerError.none,
});

/// Returns an instance for a video that hasn't been loaded.
Expand Down Expand Up @@ -135,6 +136,9 @@ class VideoPlayerValue {
/// Indicates whether or not the video has been loaded and is ready to play.
final bool isInitialized;

///
final PlayerError? playerError;

/// Indicates whether or not the video is in an error state. If this is true
/// [errorDescription] should have information about the problem.
bool get hasError => errorDescription != null;
Expand Down Expand Up @@ -174,6 +178,7 @@ class VideoPlayerValue {
double? playbackSpeed,
String? errorDescription = _defaultErrorDescription,
bool? isCompleted,
PlayerError? playerError,
}) {
return VideoPlayerValue(
duration: duration ?? this.duration,
Expand All @@ -194,6 +199,7 @@ class VideoPlayerValue {
? errorDescription
: this.errorDescription,
isCompleted: isCompleted ?? this.isCompleted,
playerError: playerError ?? PlayerError.none,
);
}

Expand All @@ -214,7 +220,8 @@ class VideoPlayerValue {
'volume: $volume, '
'playbackSpeed: $playbackSpeed, '
'errorDescription: $errorDescription, '
'isCompleted: $isCompleted),';
'isCompleted: $isCompleted, '
'playerError: $playerError';
}

@override
Expand All @@ -236,7 +243,8 @@ class VideoPlayerValue {
volume == other.volume &&
playbackSpeed == other.playbackSpeed &&
errorDescription == other.errorDescription &&
isCompleted == other.isCompleted;
isCompleted == other.isCompleted &&
playerError == other.playerError;

@override
int get hashCode => Object.hash(
Expand All @@ -255,6 +263,7 @@ class VideoPlayerValue {
playbackSpeed,
errorDescription,
isCompleted,
playerError,
);
}

Expand Down Expand Up @@ -567,7 +576,8 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
} else {
value = value.copyWith(isPlaying: event.isPlaying);
}

case VideoEventType.error:
value = value.copyWith(playerError: event.playerError);
case VideoEventType.unknown:
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,85 @@ enum DashPlayerProperty {
dashStreamInfo,
}

/// Specifies the player error messages.
enum PlayerError {
/// Operation has successfully completed; no error.
none,

/// Out of memory.
outOfMemory,

/// Unable to find the parameter.
invalidParameter,

/// Unable to find the specified media content.
noSuchFile,

/// Invalid API Call at the moment.
invalidOperation,

/// No space left on the device.
fileNoSpaceOnDevice,

/// Not supported Feature.
featureNotSupportedOnDevice,

/// Failed to perform seek operation, or seek operation called during an
/// invalid state
seekFailed,

/// AVPlay API method was called during an invalid state.
invalidState,

/// Multimedia file type not supported.
notSupportedFile,

/// Input URI is in an invalid format.
invalidUri,

/// Sound policy error.
soundPolicy,

/// Failed multiple attempts to connect to the specified content server.
connectionFailed,

/// Expired license.
drmExpired,

/// License for future use.
drmFutureUse,

/// No license.
drmNoLicense,

/// Format not permitted.
drmNotPermitted,

/// Resource limit.
resourceLimit,

/// Permission denied.
permissionDenied,

/// Socket connection lost.
serviceDisconnected,

/// No buffer space available.
bufferSpace,

/// Not supported audio codec but video can be played.
notSupportedAudioCodec,

/// Not supported video codec but audio can be played.
notSupportedVideoCodec,

/// Not supported subtitle format.
notSupportedSubtitle,

/// Multimedia file format not supported.
notSupportedFormat,
}

/// Event emitted from the platform implementation.
@immutable
class VideoEvent {
Expand All @@ -454,6 +533,7 @@ class VideoEvent {
this.buffered,
this.text,
this.isPlaying,
this.playerError,
});

/// The type of the event.
Expand Down Expand Up @@ -484,6 +564,11 @@ class VideoEvent {
/// Only used if [eventType] is [VideoEventType.isPlayingStateUpdate].
final bool? isPlaying;

/// Error event of the video.
///
/// Only used if [eventType] is [VideoEventType.error].
final PlayerError? playerError;

@override
bool operator ==(Object other) {
return identical(this, other) ||
Expand Down Expand Up @@ -534,6 +619,9 @@ enum VideoEventType {
/// phone calls, or other app media such as music players.
isPlayingStateUpdate,

/// Error messages notifications.
error,

/// An unknown event has been received.
unknown,
}
Expand Down
2 changes: 1 addition & 1 deletion packages/video_player_avplay/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: video_player_avplay
description: Flutter plugin for displaying inline video on Tizen TV devices.
homepage: https://github.com/flutter-tizen/plugins
repository: https://github.com/flutter-tizen/plugins/tree/master/packages/video_player_avplay
version: 0.5.17
version: 0.5.18

environment:
sdk: ">=3.1.0 <4.0.0"
Expand Down
49 changes: 47 additions & 2 deletions packages/video_player_avplay/tizen/src/media_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,47 @@

#include "log.h"

std::map<player_error_e, PlayerError> kMediaPlayerErrorMap = {
{player_error_e::PLAYER_ERROR_NONE, PlayerError::kNone},
{player_error_e::PLAYER_ERROR_OUT_OF_MEMORY, PlayerError::kOutOfMemory},
{player_error_e::PLAYER_ERROR_INVALID_PARAMETER,
PlayerError::kInvalidParameter},
{player_error_e::PLAYER_ERROR_NO_SUCH_FILE, PlayerError::kNoSuchFile},
{player_error_e::PLAYER_ERROR_INVALID_OPERATION,
PlayerError::kInvalidOperation},
{player_error_e::PLAYER_ERROR_FILE_NO_SPACE_ON_DEVICE,
PlayerError::kFileNoSpaceOnDevice},
{player_error_e::PLAYER_ERROR_FEATURE_NOT_SUPPORTED_ON_DEVICE,
PlayerError::kFeatureNotSupportedOnDevice},
{player_error_e::PLAYER_ERROR_SEEK_FAILED, PlayerError::kSeekFailed},
{player_error_e::PLAYER_ERROR_INVALID_STATE, PlayerError::kInvalidState},
{player_error_e::PLAYER_ERROR_NOT_SUPPORTED_FILE,
PlayerError::kNotSupportedFile},
{player_error_e::PLAYER_ERROR_INVALID_URI, PlayerError::kInvalidUri},
{player_error_e::PLAYER_ERROR_SOUND_POLICY, PlayerError::kSoundPolicy},
{player_error_e::PLAYER_ERROR_CONNECTION_FAILED,
PlayerError::kConnectionFailed},
{player_error_e::PLAYER_ERROR_DRM_EXPIRED, PlayerError::kDrmExpired},
{player_error_e::PLAYER_ERROR_DRM_NO_LICENSE, PlayerError::kDrmNoLicense},
{player_error_e::PLAYER_ERROR_DRM_FUTURE_USE, PlayerError::kDrmFutureUse},
{player_error_e::PLAYER_ERROR_DRM_NOT_PERMITTED,
PlayerError::kDrmNotPermitted},
{player_error_e::PLAYER_ERROR_RESOURCE_LIMIT, PlayerError::kResourceLimit},
{player_error_e::PLAYER_ERROR_PERMISSION_DENIED,
PlayerError::kPermissionDenied},
{player_error_e::PLAYER_ERROR_SERVICE_DISCONNECTED,
PlayerError::kServiceDisconnected},
{player_error_e::PLAYER_ERROR_BUFFER_SPACE, PlayerError::kBufferSpace},
{player_error_e::PLAYER_ERROR_NOT_SUPPORTED_AUDIO_CODEC,
PlayerError::kNotSupportedAudioCodec},
{player_error_e::PLAYER_ERROR_NOT_SUPPORTED_VIDEO_CODEC,
PlayerError::kNotSupportedVideoCodec},
{player_error_e::PLAYER_ERROR_NOT_SUPPORTED_SUBTITLE,
PlayerError::kNotSupportedSubtitle},
{player_error_e::PLAYER_ERROR_NOT_SUPPORTED_FORMAT,
PlayerError::kNotSupportedFormat},
};

static std::vector<std::string> split(const std::string &s, char delim) {
std::stringstream ss(s);
std::string item;
Expand Down Expand Up @@ -696,8 +737,12 @@ void MediaPlayer::OnError(int error_code, void *user_data) {
get_error_message(error_code));

MediaPlayer *self = static_cast<MediaPlayer *>(user_data);
self->SendError("Media Player error",
std::string("Error: ") + get_error_message(error_code));
std::map<player_error_e, PlayerError>::iterator iter =
kMediaPlayerErrorMap.find(static_cast<player_error_e>(error_code));
if (iter != kMediaPlayerErrorMap.end()) {
self->SendError(
kMediaPlayerErrorMap[static_cast<player_error_e>(error_code)]);
}
}

void MediaPlayer::OnSubtitleUpdated(unsigned long duration, char *text,
Expand Down
Loading