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

Unified 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, 6 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
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
+}
« 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