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 throw err.GetException(message);
65 internal static Exception GetException(this PlayerErrorCode err, string message)
67 if (err == PlayerErrorCode.None)
72 string msg = $"{ (message ?? "Operation failed") } : { err.ToString() }.";
76 case PlayerErrorCode.InvalidArgument:
77 case PlayerErrorCode.InvalidUri:
78 throw new ArgumentException(msg);
80 case PlayerErrorCode.NoSuchFile:
81 throw new FileNotFoundException(msg);
83 case PlayerErrorCode.OutOfMemory:
84 throw new OutOfMemoryException(msg);
86 case PlayerErrorCode.NoSpaceOnDevice:
87 throw new IOException(msg);
89 case PlayerErrorCode.PermissionDenied:
90 throw new UnauthorizedAccessException(msg);
92 case PlayerErrorCode.NotSupportedFile:
93 throw new FileFormatException(msg);
95 case PlayerErrorCode.FeatureNotSupported:
96 throw new NotSupportedException(msg);
98 case PlayerErrorCode.DrmExpired:
99 case PlayerErrorCode.DrmNoLicense:
100 case PlayerErrorCode.DrmFutureUse:
101 case PlayerErrorCode.DrmNotPermitted:
102 // TODO consider another exception.
103 case PlayerErrorCode.InvalidOperation:
104 case PlayerErrorCode.InvalidState:
105 case PlayerErrorCode.SeekFailed:
106 case PlayerErrorCode.ConnectionFailed:
107 case PlayerErrorCode.VideoCaptureFailed:
108 throw new InvalidOperationException(msg);
110 case PlayerErrorCode.NoBufferSpace:
111 throw new NoBufferSpaceException(msg);
113 case PlayerErrorCode.ResourceLimit:
114 throw new ResourceLimitException(msg);
116 case PlayerErrorCode.NotSupportedAudioCodec:
117 throw new CodecNotSupportedException(CodecKind.Audio);
119 case PlayerErrorCode.NotSupportedVideoCodec:
120 throw new CodecNotSupportedException(CodecKind.Video);
124 throw new InvalidOperationException(msg);
129 /// The exception that is thrown when there is no available space in a buffer.
131 /// <since_tizen> 3 </since_tizen>
132 public class NoBufferSpaceException : InvalidOperationException
135 /// Initializes a new instance of the NoBufferSpaceException class with a specified error message.
137 /// <param name="message">Error description.</param>
138 /// <since_tizen> 3 </since_tizen>
139 public NoBufferSpaceException(string message) : base(message)
145 /// The exception that is thrown when there is no available resource for internal use.
147 /// <since_tizen> 3 </since_tizen>
148 public class ResourceLimitException : InvalidOperationException
151 /// Initializes a new instance of the ResourceLimitException class with a specified error message.
153 /// <param name="message">Error description.</param>
154 /// <since_tizen> 3 </since_tizen>
155 public ResourceLimitException(string message) : base(message)