Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the error message.
        /// </summary>
        /// <param name="errorCode">The error code.</param>
        /// <returns>
        /// The error message text.
        /// </returns>
        private static string GetErrorMessage(PlayerErrorCode errorCode)
        {
            string message = errorCodeToMessage.ContainsKey(errorCode)
                ? errorCodeToMessage[errorCode] : Unexpected;

            return(message);
        }
Exemplo n.º 3
0
 internal static MockResponse FromPlayerError(PlayerErrorCode errorCode, string status, string message)
 {
     return(new MockResponse()
     {
         StatusCode = (int)errorCode,
         StatusDescription = status,
         Content = message
     });
 }
Exemplo n.º 4
0
        internal static void ThrowIfFailed(this PlayerErrorCode err, string message)
        {
            if (err == PlayerErrorCode.None)
            {
                return;
            }

            throw err.GetException(message);
        }
Exemplo n.º 5
0
        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;
        }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PlayerException"/> class.
 /// </summary>
 /// <param name="errorCode">The error code.</param>
 public PlayerException(PlayerErrorCode errorCode)
     : base(GetErrorMessage(errorCode))
 {
     this.ErrorCode = errorCode;
 }