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

Side by Side Diff: sky/sdk/example/widgets/piano.dart

Issue 1211913005: Add a sky media service to make it possible to play a sound. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Add example Created 5 years, 5 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 unified diff | Download patch
« no previous file with comments | « sky/apk/demo/org/domokit/sky/demo/SkyDemoApplication.java ('k') | sky/services/media/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 import 'package:sky/mojo/net/fetch.dart';
6 import 'package:mojom/media/media.mojom.dart';
7 import 'package:mojom/mojo/url_response.mojom.dart';
8 import 'package:sky/rendering/box.dart';
9 import 'package:sky/rendering/flex.dart';
10 import 'package:sky/theme/colors.dart' as colors;
11 import 'package:sky/widgets/basic.dart';
12 import 'package:sky/mojo/shell.dart' as shell;
13
14 String soundUrl = "http://soundbible.com/grab.php?id=1931&type=wav";
15
16 class Key {
17 Key(this.color);
18
19 Color color;
20 MediaPlayerProxy player;
21
22 void down() {
23 print('down ${player}');
24 if (player == null)
25 return;
26 player.ptr.seekTo(0);
27 player.ptr.start();
28 }
29
30 void up() {
31 print('up ${player}');
32 if (player == null)
33 return;
34 player.ptr.pause();
35 }
36 }
37
38 class PianoApp extends App {
39 final List<Map<int, Color> > pallets = [
abarth-chromium 2015/07/01 15:57:21 s/> >/>>/ This ain't C++!
40 colors.Red,
41 colors.Orange,
42 colors.Yellow,
43 colors.Green,
44 colors.Blue,
45 colors.Purple,
46 ];
47
48 List<Key> keys = [];
49
50 PianoApp() {
51 for (var pallet in pallets) {
52 keys.add(new Key(pallet[500]));
53 }
54 loadSounds();
55 }
56
57 loadSounds() async {
58 MediaServiceProxy mediaService = new MediaServiceProxy.unbound();
59 shell.requestService("mojo:yo_mama", mediaService);
abarth-chromium 2015/07/01 15:57:21 yo_mama!
60
61 for (Key key in keys) {
62 MediaPlayerProxy player = new MediaPlayerProxy.unbound();
63 mediaService.ptr.createPlayer(player);
64
65 UrlResponse response = await fetchUrl(soundUrl);
66 print(response);
67 await player.ptr.prepare(response.body);
68 print('PREPARED!');
69 key.player = player;
70 }
71 mediaService.close();
72 // Are we leaking all the player connections?
73 scheduleBuild();
74 }
75
76 Widget build() {
77 List<Widget> children = [];
78 for (Key key in keys) {
79 children.add(
80 new Listener(
81 child: new Flexible(
82 child: new Container(
83 decoration: new BoxDecoration(backgroundColor: key.color)
84 )
85 ),
86 onPointerCancel: (_) => key.up(),
87 onPointerDown: (_) => key.down(),
88 onPointerUp: (_) => key.up()
89 )
90 );
91 }
92
93 return new Flex(
94 children,
95 direction: FlexDirection.vertical
96 );
97 }
98 }
99
100 void main() {
101 runApp(new PianoApp());
102 }
OLDNEW
« no previous file with comments | « sky/apk/demo/org/domokit/sky/demo/SkyDemoApplication.java ('k') | sky/services/media/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698