forked from Alos/xyzradio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSMSoundManager.j
96 lines (84 loc) · 2.03 KB
/
SMSoundManager.j
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
//
// SMSoundManager.j
// SoundManager
//
// Created by Ross Boucher on 10/3/08.
// Copyright 280 North 2008. All rights reserved.
//
import <Foundation/CPObject.j>
import <AppKit/AppKit.j>
@implementation SMSoundManager : CPObject
{
BOOL isLoaded;
Object soundManager;
Object song;
}
- (id)init
{
self = [super init];
console.log("Inicializando el SM");
window.setTimeout(setupSoundManager, 1000, self);
return self;
}
- (void)soundManagerDidLoad:(Object)aManager
{
isLoaded = YES;
soundManager = aManager;
//[self playSound];
}
- (void)playSound:(CPString)aFile
{
var song = soundManager.createSound({
id : 'aSong',
url : aFile,
onfinish: function(){
[self soundDidFinish]
;},
whileplaying: function(){
[self soundPosition];
}
});
song.play();
}
-(void)pauseSound{
soundManager.pause('aSong');
}
-(void)resumeSound{
soundManager.resume('aSong');
}
-(void)togglePause{
soundManager.togglePause('aSong');
}
-(void)isLoaded
{
return isLoaded;
}
-(void)setVolume:(int)aVolume{
console.log(aVolume);
soundManager.setVolume('aSong', aVolume);
}
-(void)soundDidFinish{
console.log("Sound finished...posting notification...");
[[CPNotificationCenter defaultCenter] postNotificationName:"SongEnded" object:self];
}
-(void)soundPosition{
var info = [CPDictionary dictionaryWithObject:song.position forKey:"time"];
[[CPNotificationCenter defaultCenter] postNotificationName:"pos" object:self userInfo:info];
}
@end
var setupSoundManager = function(obj)
{
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "Resources/soundmanager2.js";
script.addEventListener("load", function()
{
soundManager.url = "Resources/"; // path to directory containing SoundManager2 .SWF file
soundManager.onload = function() {
[obj soundManagerDidLoad:soundManager];
};
soundManager.beginDelayedInit();
soundManager.debugMode = false;
}, YES);
document.getElementsByTagName("head")[0].appendChild(script);
}