Chromium Code Reviews| Index: sky/sdk/example/widgets/piano.dart |
| diff --git a/sky/sdk/example/widgets/piano.dart b/sky/sdk/example/widgets/piano.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b8217b4bd8e3f778c565248658bb431f856c78db |
| --- /dev/null |
| +++ b/sky/sdk/example/widgets/piano.dart |
| @@ -0,0 +1,102 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +import 'package:sky/mojo/net/fetch.dart'; |
| +import 'package:mojom/media/media.mojom.dart'; |
| +import 'package:mojom/mojo/url_response.mojom.dart'; |
| +import 'package:sky/rendering/box.dart'; |
| +import 'package:sky/rendering/flex.dart'; |
| +import 'package:sky/theme/colors.dart' as colors; |
| +import 'package:sky/widgets/basic.dart'; |
| +import 'package:sky/mojo/shell.dart' as shell; |
| + |
| +String soundUrl = "http://soundbible.com/grab.php?id=1931&type=wav"; |
| + |
| +class Key { |
| + Key(this.color); |
| + |
| + Color color; |
| + MediaPlayerProxy player; |
| + |
| + void down() { |
| + print('down ${player}'); |
| + if (player == null) |
| + return; |
| + player.ptr.seekTo(0); |
| + player.ptr.start(); |
| + } |
| + |
| + void up() { |
| + print('up ${player}'); |
| + if (player == null) |
| + return; |
| + player.ptr.pause(); |
| + } |
| +} |
| + |
| +class PianoApp extends App { |
| + final List<Map<int, Color> > pallets = [ |
|
abarth-chromium
2015/07/01 15:57:21
s/> >/>>/
This ain't C++!
|
| + colors.Red, |
| + colors.Orange, |
| + colors.Yellow, |
| + colors.Green, |
| + colors.Blue, |
| + colors.Purple, |
| + ]; |
| + |
| + List<Key> keys = []; |
| + |
| + PianoApp() { |
| + for (var pallet in pallets) { |
| + keys.add(new Key(pallet[500])); |
| + } |
| + loadSounds(); |
| + } |
| + |
| + loadSounds() async { |
| + MediaServiceProxy mediaService = new MediaServiceProxy.unbound(); |
| + shell.requestService("mojo:yo_mama", mediaService); |
|
abarth-chromium
2015/07/01 15:57:21
yo_mama!
|
| + |
| + for (Key key in keys) { |
| + MediaPlayerProxy player = new MediaPlayerProxy.unbound(); |
| + mediaService.ptr.createPlayer(player); |
| + |
| + UrlResponse response = await fetchUrl(soundUrl); |
| + print(response); |
| + await player.ptr.prepare(response.body); |
| + print('PREPARED!'); |
| + key.player = player; |
| + } |
| + mediaService.close(); |
| + // Are we leaking all the player connections? |
| + scheduleBuild(); |
| + } |
| + |
| + Widget build() { |
| + List<Widget> children = []; |
| + for (Key key in keys) { |
| + children.add( |
| + new Listener( |
| + child: new Flexible( |
| + child: new Container( |
| + decoration: new BoxDecoration(backgroundColor: key.color) |
| + ) |
| + ), |
| + onPointerCancel: (_) => key.up(), |
| + onPointerDown: (_) => key.down(), |
| + onPointerUp: (_) => key.up() |
| + ) |
| + ); |
| + } |
| + |
| + return new Flex( |
| + children, |
| + direction: FlexDirection.vertical |
| + ); |
| + } |
| +} |
| + |
| +void main() { |
| + runApp(new PianoApp()); |
| +} |