internal static Exception GetException(this PlayerErrorCode err, string message) { if (err == PlayerErrorCode.None) { return(null); } string msg = $"{ (message ?? "Operation failed") } : { err.ToString() }."; switch (err) { case PlayerErrorCode.InvalidArgument: case PlayerErrorCode.InvalidUri: throw new ArgumentException(msg); case PlayerErrorCode.NoSuchFile: throw new FileNotFoundException(msg); case PlayerErrorCode.OutOfMemory: throw new OutOfMemoryException(msg); case PlayerErrorCode.NoSpaceOnDevice: throw new IOException(msg); case PlayerErrorCode.PermissionDenied: throw new UnauthorizedAccessException(msg); case PlayerErrorCode.NotSupportedFile: throw new FileFormatException(msg); case PlayerErrorCode.FeatureNotSupported: throw new NotSupportedException(msg); case PlayerErrorCode.DrmExpired: case PlayerErrorCode.DrmNoLicense: case PlayerErrorCode.DrmFutureUse: case PlayerErrorCode.DrmNotPermitted: // TODO consider another exception. case PlayerErrorCode.InvalidOperation: case PlayerErrorCode.InvalidState: case PlayerErrorCode.SeekFailed: case PlayerErrorCode.ConnectionFailed: case PlayerErrorCode.VideoCaptureFailed: throw new InvalidOperationException(msg); case PlayerErrorCode.NoBufferSpace: throw new NoBufferSpaceException(msg); case PlayerErrorCode.ResourceLimit: throw new ResourceLimitException(msg); case PlayerErrorCode.NotSupportedAudioCodec: throw new CodecNotSupportedException(CodecKind.Audio); case PlayerErrorCode.NotSupportedVideoCodec: throw new CodecNotSupportedException(CodecKind.Video); } return(null); }
internal static void ThrowIfFailed(this PlayerErrorCode err, Player player, string message) { if (err == PlayerErrorCode.None) { return; } var ex = err.GetException(message); if (ex == null) { // Notify only when it can't be handled. player?.NotifyError((int)err, message); throw new InvalidOperationException($"{message} : Unknown error({err.ToString()})."); } throw ex; }