1 /***
2 * Ambient - A music player for the Android platform
3 Copyright (C) 2007 Martin Vysny
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 package sk.baka.ambient.playerservice;
20
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import sk.baka.ambient.R;
25
26 import android.content.Context;
27 import android.media.MediaPlayer;
28
29 /***
30 * Decodes {@link MediaPlayer} error codes.
31 *
32 * @author Martin Vysny
33 */
34 public final class MediaPlayerErrors {
35 private MediaPlayerErrors() {
36 throw new Error();
37 }
38
39 private final static Map<Integer, String> WHAT_TO_TEXT = new HashMap<Integer, String>();
40 static {
41 WHAT_TO_TEXT.put(MediaPlayer.MEDIA_ERROR_UNKNOWN, "ERROR_UNKNOWN");
42 WHAT_TO_TEXT.put(MediaPlayer.MEDIA_ERROR_SERVER_DIED,
43 "ERROR_SERVER_DIED");
44 }
45
46 /***
47 * Formats given {@link MediaPlayer} error message.
48 *
49 * @param what
50 * the "What" field.
51 * @param extra
52 * the "Extra" field.
53 * @param context
54 * a context
55 * @return error message.
56 */
57 public static String getMessage(final int what, final int extra,
58 final Context context) {
59 final StringBuilder b = new StringBuilder();
60 b.append(context.getString(R.string.mediaPlayerError));
61 b.append(": ");
62 final String error = WHAT_TO_TEXT.get(what);
63 if (error == null) {
64 b.append("ERROR_UNKNOWN (");
65 b.append(what);
66 b.append(")");
67 } else {
68 b.append(error);
69 }
70 b.append("; Additional information: ");
71 b.append(extra);
72 return b.toString();
73 }
74 }