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.collection;
20
21 import sk.baka.ambient.library.LibraryUtils;
22
23 /***
24 * The location of the track.
25 *
26 * @author Martin Vysny
27 */
28 public enum TrackOriginEnum {
29 /***
30 * The local filesystem.
31 */
32 LocalFs(null, false, true, false),
33 /***
34 * <a href="http://www.magnatune.com">Magnatune</a> shop.
35 */
36 Magnatune("http://www.magnatune.com", true, true, false),
37 /***
38 * <a href="http://www.skreemr.com">SkreemR</a> search engine.
39 */
40 SkreemR("http://www.skreemr.com", true, true, false),
41 /***
42 * A <a href="http://www.shoutcast.com">SHOUTcast</a> radio station.
43 */
44 Shoutcast("http://www.shoutcast.com", true, false, true),
45 /***
46 * <a href="http://www.skreemr.com">Ampache</a> music library.
47 */
48 Ampache("http://ampache.org", true, true, false);
49 private TrackOriginEnum(final String url, final boolean online,
50 final boolean seekable, final boolean endless) {
51 this.url = url;
52 this.online = online;
53 this.seekable = seekable;
54 this.endless = endless;
55 }
56
57 /***
58 * If <code>true</code> then this stream type is endless (like an Internet
59 * radio). If <code>false</code> then the stream type is a finite file.
60 */
61 public final boolean endless;
62
63 /***
64 * If <code>true</code> then media player is able to seek in this media
65 * type.
66 */
67 public final boolean seekable;
68
69 /***
70 * The track location URL. May be <code>null</code> if there is no
71 * particular URL.
72 */
73 public final String url;
74 /***
75 * If <code>true</code> then tracks from this location are stored on-line.
76 */
77 public final boolean online;
78
79 /***
80 * Gets the enum constant from a DB INT value.
81 *
82 * @param val
83 * the value
84 * @return the constant.
85 */
86 public static TrackOriginEnum fromDb(final int val) {
87 return TrackOriginEnum.values()[val];
88 }
89
90 /***
91 * Gets the track type from its location.
92 *
93 * @param location
94 * the location.
95 * @return the constant.
96 */
97 public static TrackOriginEnum fromLocation(final String location) {
98 if (!location.startsWith("http://")) {
99 return TrackOriginEnum.LocalFs;
100 }
101 final String hostLoc = location.substring(7);
102 if (LibraryUtils.MUSIC_NAME_FILTER.accept(null, hostLoc)) {
103 return TrackOriginEnum.SkreemR;
104 }
105 return TrackOriginEnum.Shoutcast;
106 }
107
108 /***
109 * Returns the enum value as a database string. This string is passable for
110 * example to the {@link ICollection} finder method.
111 *
112 * @return a DB representation of this enum.
113 */
114 public String toDBString() {
115 return String.valueOf(ordinal());
116 }
117 }