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

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: Updated per review 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:mojom/media/media.mojom.dart';
6 import 'package:mojom/mojo/url_response.mojom.dart';
7 import 'package:sky/mojo/net/fetch.dart';
8 import 'package:sky/mojo/shell.dart' as shell;
9 import 'package:sky/rendering/box.dart';
10 import 'package:sky/rendering/flex.dart';
11 import 'package:sky/theme/colors.dart' as colors;
12 import 'package:sky/widgets/basic.dart';
13
14 // All of these sounds are marked as public domain at soundbible.
15 const String chimes = "http://soundbible.com/grab.php?id=2030&type=wav";
16 const String chainsaw = "http://soundbible.com/grab.php?id=1391&type=wav";
17 const String stag = "http://soundbible.com/grab.php?id=2073&type=wav";
18 const String frogs = "http://soundbible.com/grab.php?id=2033&type=wav";
19 const String rattle = "http://soundbible.com/grab.php?id=2037&type=wav";
20 const String iLoveYou = "http://soundbible.com/grab.php?id=2045&type=wav";
21
22 class Key {
23 Key(this.color, this.soundUrl);
24
25 final Color color;
26 final String soundUrl;
27 MediaPlayerProxy player;
28
29 void down() {
30 if (player == null)
31 return;
32 player.ptr.seekTo(0);
33 player.ptr.start();
34 }
35
36 void up() {
37 if (player == null)
38 return;
39 player.ptr.pause();
40 }
41 }
42
43 class PianoApp extends App {
44 final List<Key> keys = [
45 new Key(colors.Red[500], chimes),
46 new Key(colors.Orange[500], chainsaw),
47 new Key(colors.Yellow[500], stag),
48 new Key(colors.Green[500], frogs),
49 new Key(colors.Blue[500], rattle),
50 new Key(colors.Purple[500], iLoveYou),
51 ];
52
53 PianoApp() {
54 loadSounds();
55 }
56
57 loadSounds() async {
58 MediaServiceProxy mediaService = new MediaServiceProxy.unbound();
59 shell.requestService(null, mediaService);
60
61 for (Key key in keys) {
62 MediaPlayerProxy player = new MediaPlayerProxy.unbound();
63 mediaService.ptr.createPlayer(player);
64
65 UrlResponse response = await fetchUrl(key.soundUrl);
66 await player.ptr.prepare(response.body);
67 key.player = player;
68 }
69 mediaService.close();
70 // Are we leaking all the player connections?
71 scheduleBuild();
72 }
73
74 Widget build() {
75 List<Widget> children = [];
76 for (Key key in keys) {
77 children.add(
78 new Listener(
79 child: new Flexible(
80 child: new Container(
81 decoration: new BoxDecoration(backgroundColor: key.color)
82 )
83 ),
84 onPointerCancel: (_) => key.up(),
85 onPointerDown: (_) => key.down(),
86 onPointerUp: (_) => key.up()
87 )
88 );
89 }
90
91 return new Flex(
92 children,
93 direction: FlexDirection.vertical
94 );
95 }
96 }
97
98 void main() {
99 runApp(new PianoApp());
100 }
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