2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using Tizen.Internals.Errors;
20 namespace Tizen.Multimedia
22 internal enum PlayerErrorCode
24 None = ErrorCode.None,
25 InvalidArgument = ErrorCode.InvalidParameter,
26 OutOfMemory = ErrorCode.OutOfMemory,
27 NoSuchFile = ErrorCode.NoSuchFile,
28 InvalidOperation = ErrorCode.InvalidOperation,
29 NoSpaceOnDevice = ErrorCode.FileNoSpaceOnDevice,
30 FeatureNotSupported = ErrorCode.NotSupported,
31 PermissionDenied = ErrorCode.PermissionDenied,
32 NoBufferSpace = ErrorCode.BufferSpace,
33 TizenPlayerError = -0x01940000,
34 PlayerErrorClass = TizenPlayerError | 0x20,
35 SeekFailed = PlayerErrorClass | 0x01,
36 InvalidState = PlayerErrorClass | 0x02,
37 NotSupportedFile = PlayerErrorClass | 0x03,
38 InvalidUri = PlayerErrorClass | 0x04,
39 SoundPolicyError = PlayerErrorClass | 0x05,
40 ConnectionFailed = PlayerErrorClass | 0x06,
41 VideoCaptureFailed = PlayerErrorClass | 0x07,
42 DrmExpired = PlayerErrorClass | 0x08,
43 DrmNoLicense = PlayerErrorClass | 0x09,
44 DrmFutureUse = PlayerErrorClass | 0x0a,
45 DrmNotPermitted = PlayerErrorClass | 0x0b,
46 ResourceLimit = PlayerErrorClass | 0x0c,
47 ServiceDisconnected = PlayerErrorClass | 0x0d,
48 NotSupportedAudioCodec = PlayerErrorClass | 0x0e,
49 NotSupportedVideoCodec = PlayerErrorClass | 0x0f,
50 NotSupportedSubtitle = PlayerErrorClass | 0x10
53 internal static class PlayerErrorCodeExtensions
55 internal static void ThrowIfFailed(this PlayerErrorCode err, string message)
57 if (err == PlayerErrorCode.None)
62 string msg = $"{ (message ?? "Operation failed") } : { err.ToString() }.";
66 case PlayerErrorCode.InvalidArgument:
67 case PlayerErrorCode.InvalidUri:
68 throw new ArgumentException(msg);
70 case PlayerErrorCode.NoSuchFile:
71 throw new FileNotFoundException(msg);
73 case PlayerErrorCode.OutOfMemory:
74 throw new OutOfMemoryException(msg);
76 case PlayerErrorCode.NoSpaceOnDevice:
77 throw new IOException(msg);
79 case PlayerErrorCode.PermissionDenied:
80 throw new UnauthorizedAccessException(msg);
82 case PlayerErrorCode.NotSupportedFile:
83 throw new FileFormatException(msg);
85 case PlayerErrorCode.FeatureNotSupported:
86 throw new NotSupportedException(msg);
88 case PlayerErrorCode.DrmExpired:
89 case PlayerErrorCode.DrmNoLicense:
90 case PlayerErrorCode.DrmFutureUse:
91 case PlayerErrorCode.DrmNotPermitted:
92 // TODO consider another exception.
93 case PlayerErrorCode.InvalidOperation:
94 case PlayerErrorCode.InvalidState:
95 case PlayerErrorCode.SeekFailed:
96 case PlayerErrorCode.ConnectionFailed:
97 case PlayerErrorCode.VideoCaptureFailed:
98 throw new InvalidOperationException(msg);
100 case PlayerErrorCode.NoBufferSpace:
101 throw new NoBufferSpaceException(msg);
103 case PlayerErrorCode.ResourceLimit:
104 throw new ResourceLimitException(msg);
106 case PlayerErrorCode.NotSupportedAudioCodec:
107 throw new CodecNotSupportedException(CodecKind.Audio);
109 case PlayerErrorCode.NotSupportedVideoCodec:
110 throw new CodecNotSupportedException(CodecKind.Video);
114 throw new Exception(msg);
119 /// The exception that is thrown when there is no available space in a buffer.
121 public class NoBufferSpaceException : InvalidOperationException
124 /// Initializes a new instance of the NoBufferSpaceException class with a specified error message.
126 /// <param name="message">Error description.</param>
127 public NoBufferSpaceException(string message) : base(message)
133 /// The exception that is thrown when there is no available resource for internal use.
135 public class ResourceLimitException : InvalidOperationException
138 /// Initializes a new instance of the ResourceLimitException class with a specified error message.
140 /// <param name="message">Error description.</param>
141 public ResourceLimitException(string message) : base(message)