forked from fbricker/muses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MusesRadioPlayer.hx
190 lines (161 loc) · 5.45 KB
/
MusesRadioPlayer.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
////////////////////////////////////////////////////////////////////////////////
//
// Muses Radio Player - Radio Streaming player written in Haxe.
//
// Copyright (C) 2009-2013 Federico Bricker
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// This Project was initially based on FOggPlayer by Bill Farmer. So
// my special thanks to him! :)
//
// Federico Bricker f bricker [at] gmail [dot] com.
//
////////////////////////////////////////////////////////////////////////////////
import flash.Lib;
import flash.system.Capabilities;
import flash.system.Security;
import internationalization.AbstractLanguage;
import internationalization.LanguageFactory;
// MusesRadioPlayer Main class
class MusesRadioPlayer{
var url : String;
var introUrl : String;
var fallbackUrl : String;
var autoplay : Bool;
var player : Player;
var ui : UI;
var lang : String;
var codec : String;
var tracking : Bool;
var volume : Int;
var welcome : String;
var buffering : Int;
var metadataInterval : Int;
var usesMetadataLoader : String;
var metadataLoader : MetadataLoader;
var metadataUrl : String;
var metadataProxy : String;
var reconnectTime : Int;
public static var SKIN:String = 'default';
public static var VERSION = "1.2";
public static var FPS:Int = 12;
// Kick things off
public static function main(){
var musesRadioPlayer = new MusesRadioPlayer();
// calling garbage collector every 5 secs. just in case.
new haxe.Timer(5000).run = flash.system.System.gc;
}
// Create a new Player
function new(){
metadataLoader = null;
if (Lib.current.loaderInfo.parameters.skin != null) {
MusesRadioPlayer.SKIN = Lib.current.loaderInfo.parameters.skin;
}
// Create the UI
ui = switch(MusesRadioPlayer.SKIN) {
case 'default': new skins.Default();
case 'original': new skins.Default();
case 'tiny': new skins.Tiny();
default: new skins.Configurable(Lib.current.loaderInfo.parameters);
}
ui.setLanguage(LanguageFactory.factory(Capabilities.language));
flash.Lib.current.addChild(ui);
// If there's an Error in FlashVars, crate ContextMenu and abort.
if (!getParameters()) {
ui.buildContextMenu();
return;
}
if (lang != "auto" && lang != Capabilities.language) {
ui.setLanguage(LanguageFactory.factory(lang));
}
ui.buildContextMenu();
switch (codec) {
case "ogg": player = new OggPlayer(ui, url, new Tracker(tracking), fallbackUrl, introUrl);
case "aac": player = new AacPlayer(ui, url, new Tracker(tracking), fallbackUrl, introUrl);
default: player = new Mp3Player(ui, url, new Tracker(tracking), fallbackUrl, introUrl, reconnectTime);
}
ui.enable(player);
ui.volumeControl.setVolume(volume/100.0);
ui.showInfo(welcome);
player.setBuffering(buffering);
if(autoplay){ // If autoplay, then start playing (LOL)
player.jsPlaySound();
}
if(usesMetadataLoader != "false"){
metadataLoader = new MetadataLoader(player, ui, metadataInterval, usesMetadataLoader,metadataProxy,metadataUrl);
}
}
// Get the url and title
function getParameters() : Bool{
var pars : Dynamic<String> = Lib.current.loaderInfo.parameters;
Security.allowDomain('*');
// Check the url
if (pars.url == null) {
ui.setDefaultTitle("No URL");
return false;
}
// If there's a url, see if there's a title
url = pars.url;
codec = pars.codec;
lang = pars.lang;
fallbackUrl = pars.fallback;
introUrl = (pars.introurl!=null)?pars.introurl:'';
ui.setDefaultTitle((pars.title != null)?pars.title:("No Title: " + url));
// Check for autoplay
if (pars.autoplay == null || pars.autoplay == 'false' ){
autoplay=false;
}else{
autoplay=true;
}
// Buffering time
if (pars.buffering == null){
buffering=0;
}else{
buffering=Std.parseInt(StringTools.trim(pars.buffering));
}
// Check javascript events callback
if (pars.jsevents == 'true' ){
ui.enableJsEvents();
}
if (pars.volume == null){
volume=100;
}else{
volume=Std.parseInt(StringTools.trim(pars.volume));
}
if (pars.interval != null) {
metadataInterval = Std.parseInt(StringTools.trim(pars.interval));
}else {
metadataInterval = 20;
}
usesMetadataLoader = switch( pars.querymetadata ) {
case "icecast": "icecast";
case "shoutcast": "shoutcast";
case "streamtheworld": "streamtheworld";
default: "false";
}
metadataProxy = null;
if (pars.metadataproxy != null && StringTools.trim(pars.metadataproxy) != '') {
metadataProxy = StringTools.trim(pars.metadataproxy);
}
reconnectTime = (pars.reconnecttime == null)?3600:Std.parseInt(StringTools.trim(pars.reconnecttime));
if (pars.murl != null) {
metadataUrl = pars.murl;
}
welcome=pars.welcome;
tracking=(pars.tracking!='false');
return true;
}
}