Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(502)

Unified Diff: samples/third_party/pop-pop-win/web/_audio.dart

Issue 200723008: samples/poppopwin: upgrade to first-class sample (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fixed pkgbuild.status for rename Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: samples/third_party/pop-pop-win/web/_audio.dart
diff --git a/samples/third_party/pop-pop-win/web/_audio.dart b/samples/third_party/pop-pop-win/web/_audio.dart
deleted file mode 100644
index c9fa293b92d932036f759d8f869b1080bf6896b7..0000000000000000000000000000000000000000
--- a/samples/third_party/pop-pop-win/web/_audio.dart
+++ /dev/null
@@ -1,129 +0,0 @@
-part of game;
-
-class _Audio {
- static const List<String> _AUDIO_NAMES =
- const ['Pop0', 'Pop1', 'Pop2', 'Pop3', 'Pop4', 'Pop5', 'Pop6', 'Pop7', 'Pop8',
- 'Bomb0', 'Bomb1', 'Bomb2', 'Bomb3', 'Bomb4',
- GameAudio.THROW_DART, GameAudio.FLAG, GameAudio.UNFLAG, GameAudio.CLICK, GameAudio.WIN];
-
- final AudioLoader _audioLoader;
- final Map<String, AudioBuffer> _buffers = new Map();
- static final _audioFormat = _getAudioFormat();
-
- factory _Audio() {
- if(_audioFormat != null) {
- try {
- final audioContext = new AudioContext();
- final loader = new AudioLoader(audioContext, _getAudioPaths(_AUDIO_NAMES));
- return new _Audio._internal(loader);
- } catch (e) {
- print("Error creating AudioContext: ${e}");
- }
- }
- return new _Audio._disabled();
- }
-
- _Audio._disabled() : this._audioLoader = null;
-
- _Audio._internal(this._audioLoader) {
- // TODO: less than ideal. Binding to event handlers defined in game.dart
- // re-expose events? Take in handlers in ctor? Hmm...
- _audioLoader.progress.listen(_onProgress);
- _audioLoader.loaded.listen(_onLoaded);
- _audioLoader.loaded.listen(_onLoad);
- GameAudio.audioEvent.listen(_playAudio);
- _audioLoader.load();
- }
-
- int get completedBytes {
- if(_audioLoader == null) {
- return 0;
- } else {
- return _audioLoader.completedBytes;
- }
- }
-
- int get totalBytes {
- if(_audioLoader == null) {
- return 0;
- } else {
- return _audioLoader.totalBytes;
- }
- }
-
- bool get done {
- if(_audioLoader == null) {
- return true;
- } else {
- return _audioLoader.state == ResourceLoader.StateLoaded;
- }
- }
-
- AudioContext get _audioContext {
- if(_audioLoader != null) {
- return _audioLoader.context;
- } else {
- return null;
- }
- }
-
- void _onLoad(args) {
- assert(_buffers.length == 0);
- for(final name in _AUDIO_NAMES) {
- final path = _getAudioPath(name);
- _buffers[name] = _audioLoader.getResource(path);
- }
- }
-
- void _playAudio(String name) {
- switch(name) {
- case GameAudio.POP:
- final i = rnd.nextInt(8);
- name = '${GameAudio.POP}$i';
- break;
- case GameAudio.BOMB:
- final i = rnd.nextInt(4);
- name = '${GameAudio.BOMB}$i';
- break;
- }
- _playAudioCore(name);
- }
-
- void _playAudioCore(String name) {
- if(_audioContext != null) {
- var source = _audioContext.createBufferSource();
- final buffer = _buffers[name];
- assert(buffer != null);
- source.buffer = buffer;
- source.connectNode(_audioContext.destination);
- source.start(0);
- }
- }
-
- static String _getAudioFormat() {
- try {
- final userAgent = window.navigator.userAgent;
- final isWebKit = userAgent.contains("WebKit");
- if(isWebKit) {
- final isChrome = userAgent.contains("Chrome");
- if(isChrome) {
- return 'webm';
- } else {
- return 'm4a';
- }
- }
- } catch (e) {
- print("Error getting client info: ${e}");
- }
- return null;
- }
-
- static String _getAudioPath(String name) {
- assert(_audioFormat != null);
- return 'audio/${_audioFormat}/$name.${_audioFormat}';
- }
-
- static Iterable<String> _getAudioPaths(Iterable<String> names) {
- return names.map(_getAudioPath);
- }
-}
« no previous file with comments | « samples/third_party/pop-pop-win/tool/hop_runner.dart ('k') | samples/third_party/pop-pop-win/web/audio/m4a/Bomb0.m4a » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698