Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
a750da56
Commit
a750da56
authored
Aug 13, 2015
by
Viktor Lidholt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds a SoundTrackPlayer class
parent
3d31273e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
0 deletions
+73
-0
sound.dart
examples/game/lib/sound.dart
+73
-0
No files found.
examples/game/lib/sound.dart
View file @
a750da56
...
@@ -156,3 +156,76 @@ class SoundEffectPlayer {
...
@@ -156,3 +156,76 @@ class SoundEffectPlayer {
_playingSounds
=
[];
_playingSounds
=
[];
}
}
}
}
typedef
void
SoundTrackCallback
(
SoundTrack
);
typedef
void
SoundTrackBufferingCallback
(
SoundTrack
,
int
);
class
SoundTrack
{
MediaPlayerProxy
_player
;
SoundTrackCallback
onSoundComplete
;
SoundTrackCallback
onSeekComplete
;
SoundTrackBufferingCallback
onBufferingUpdate
;
bool
loop
;
double
time
;
}
SoundTrackPlayer
_sharedSoundTrackPlayer
;
class
SoundTrackPlayer
{
List
<
SoundTrack
>
_soundTracks
=
[];
static
sharedInstance
()
{
if
(
_sharedSoundTrackPlayer
==
null
)
{
_sharedSoundTrackPlayer
=
new
SoundTrackPlayer
();
}
return
_sharedSoundTrackPlayer
;
}
SoundTrackPlayer
()
{
_mediaService
=
new
MediaServiceProxy
.
unbound
();
shell
.
requestService
(
null
,
_mediaService
);
}
MediaServiceProxy
_mediaService
;
Future
<
SoundTrack
>
load
(
String
url
)
async
{
// Create media player
SoundTrack
soundTrack
=
new
SoundTrack
();
soundTrack
.
_player
=
new
MediaPlayerProxy
.
unbound
();
_mediaService
.
ptr
.
createPlayer
(
soundTrack
.
_player
);
// Load and prepare
UrlResponse
response
=
await
fetchUrl
(
url
);
await
soundTrack
.
_player
.
ptr
.
prepare
(
response
.
body
);
return
soundTrack
;
}
void
unload
(
SoundTrack
soundTrack
)
{
stop
(
soundTrack
);
_soundTracks
.
remove
(
soundTrack
);
}
void
play
(
SoundTrack
soundTrack
,
[
bool
loop
=
false
,
double
volume
,
double
startTime
=
0.0
])
{
// TODO: Implement looping & volume
// soundTrack._player.ptr.setLooping(loop);
// soundTrack._player.ptr.setVolume(volume);
soundTrack
.
_player
.
ptr
.
seekTo
((
startTime
*
1000.0
).
toInt
());
soundTrack
.
_player
.
ptr
.
start
();
}
void
stop
(
SoundTrack
track
)
{
track
.
_player
.
ptr
.
pause
();
}
void
stopAll
()
{
for
(
SoundTrack
soundTrack
in
_soundTracks
)
{
soundTrack
.
_player
.
ptr
.
pause
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment