[mediaplayer] migrate to new bindings and dart sdk
Change-Id: I3fe63e0fa032a2db5925932b8f73bcb085d9d565
diff --git a/examples/mediaplayer/mediaplayer_flutter/BUILD.gn b/examples/mediaplayer/mediaplayer_flutter/BUILD.gn
index 310916e..5f8fe51 100644
--- a/examples/mediaplayer/mediaplayer_flutter/BUILD.gn
+++ b/examples/mediaplayer/mediaplayer_flutter/BUILD.gn
@@ -20,7 +20,9 @@
"//third_party/dart-pkg/git/flutter/packages/flutter",
"//topaz/public/dart/fidl",
"//topaz/public/dart/fuchsia",
- "//topaz/public/lib/app/dart",
+ "//topaz/public/dart/fuchsia_logger",
+ "//topaz/public/dart/fuchsia_modular",
+ "//topaz/public/dart/fuchsia_services",
"//topaz/public/lib/mediaplayer/flutter",
]
},
diff --git a/examples/mediaplayer/mediaplayer_flutter/lib/main.dart b/examples/mediaplayer/mediaplayer_flutter/lib/main.dart
index 7b67c6c..167a7c8 100644
--- a/examples/mediaplayer/mediaplayer_flutter/lib/main.dart
+++ b/examples/mediaplayer/mediaplayer_flutter/lib/main.dart
@@ -5,48 +5,22 @@
import 'dart:async';
import 'dart:io' as io;
-import 'package:fidl/fidl.dart';
-import 'package:fidl_fuchsia_media/fidl.dart' as media;
-import 'package:fidl_fuchsia_media_playback/fidl.dart' as playback;
-import 'package:fidl_fuchsia_modular/fidl.dart';
+import 'package:fidl_fuchsia_media/fidl_async.dart' as media;
+import 'package:fidl_fuchsia_media_playback/fidl_async.dart' as playback;
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
-import 'package:fuchsia/fuchsia.dart';
-import 'package:lib.app.dart/app.dart';
+import 'package:fuchsia_logger/logger.dart';
+import 'package:fuchsia_modular/module.dart';
+import 'package:fuchsia_services/services.dart';
import 'package:lib.mediaplayer.flutter/media_player.dart';
import 'package:lib.mediaplayer.flutter/media_player_controller.dart';
import 'asset.dart';
import 'config.dart';
-final StartupContext _context = StartupContext.fromStartupInfo();
+final _context = StartupContext.fromStartupInfo();
final MediaPlayerController _controller =
- MediaPlayerController(_context.environmentServices);
-
-ModuleImpl _module = ModuleImpl();
-
-void _log(String msg) {
- print('[mediaplayer_flutter Module] $msg');
-}
-
-/// An implementation of the [Lifecycle] interface, which controls the lifetime
-/// of the module.
-class ModuleImpl implements Lifecycle {
- final LifecycleBinding _lifecycleBinding = LifecycleBinding();
-
- /// Binds an [InterfaceRequest] for a [Lifecycle] interface to this object.
- void bindLifecycle(InterfaceRequest<Lifecycle> request) {
- _lifecycleBinding.bind(this, request);
- }
-
- /// Implementation of Lifecycle.Terminate method.
- @override
- void terminate() {
- _log('ModuleImpl::Terminate call');
- _lifecycleBinding.close();
- exit(0);
- }
-}
+ MediaPlayerController(_context.incoming);
const List<String> _configFileNames = <String>[
'/data/mediaplayer_flutter.config',
@@ -237,16 +211,10 @@
Colors.white,
20.0,
columnChildren);
- _addLabel(
- metadata[media.metadataLabelArtist] ?? _leafAssetToPlay.artist,
- Colors.grey[600],
- 15.0,
- columnChildren);
- _addLabel(
- metadata[media.metadataLabelAlbum] ?? _leafAssetToPlay.album,
- Colors.grey[800],
- 15.0,
- columnChildren);
+ _addLabel(metadata[media.metadataLabelArtist] ?? _leafAssetToPlay.artist,
+ Colors.grey[600], 15.0, columnChildren);
+ _addLabel(metadata[media.metadataLabelAlbum] ?? _leafAssetToPlay.album,
+ Colors.grey[800], 15.0, columnChildren);
}
_addProblem(columnChildren);
@@ -390,15 +358,11 @@
}
Future<Null> main() async {
- _log('Module started');
+ setupLogger(name: 'mediaplayer_flutter Module');
+ log.fine('Module started');
- /// Add [ModuleImpl] to this application's outgoing ServiceProvider.
- _context.outgoingServices.addServiceForName(
- (InterfaceRequest<Lifecycle> request) {
- _module.bindLifecycle(request);
- },
- Lifecycle.$serviceName,
- );
+ // explicitly opt out of intents
+ Module().registerIntentHandler(NoopIntentHandler());
await _readConfig();
@@ -413,8 +377,7 @@
runApp(MaterialApp(
title: 'Media Player',
- home:
- _assets.length == 1 ? const _PlaybackScreen() : _ChooserScreen(),
+ home: _assets.length == 1 ? const _PlaybackScreen() : _ChooserScreen(),
routes: <String, WidgetBuilder>{
'/play': (BuildContext context) => const _PlaybackScreen()
},
diff --git a/public/lib/mediaplayer/dart/BUILD.gn b/public/lib/mediaplayer/dart/BUILD.gn
index 6181d62..fa09e94 100644
--- a/public/lib/mediaplayer/dart/BUILD.gn
+++ b/public/lib/mediaplayer/dart/BUILD.gn
@@ -22,7 +22,6 @@
"//sdk/fidl/fuchsia.media.playback",
"//sdk/fidl/fuchsia.net.oldhttp",
"//topaz/public/dart/fidl",
- "//topaz/public/lib/app/dart",
"//topaz/public/lib/settings:settings_protos",
]
}
diff --git a/public/lib/mediaplayer/dart/audio_player_controller.dart b/public/lib/mediaplayer/dart/audio_player_controller.dart
index ae541fc..ecebc5c 100644
--- a/public/lib/mediaplayer/dart/audio_player_controller.dart
+++ b/public/lib/mediaplayer/dart/audio_player_controller.dart
@@ -5,11 +5,10 @@
import 'dart:async';
import 'dart:io';
-import 'package:fidl_fuchsia_media_playback/fidl.dart';
-import 'package:fidl_fuchsia_net_oldhttp/fidl.dart';
-import 'package:fidl_fuchsia_sys/fidl.dart';
-import 'package:fidl_fuchsia_math/fidl.dart' as geom;
-import 'package:lib.app.dart/app.dart';
+import 'package:fidl_fuchsia_media_playback/fidl_async.dart';
+import 'package:fidl_fuchsia_net_oldhttp/fidl_async.dart';
+import 'package:fidl_fuchsia_math/fidl_async.dart' as geom;
+import 'package:fuchsia_services/services.dart';
import 'package:lib.mediaplayer.dart/timeline.dart' as tl;
import 'package:zircon/zircon.dart';
@@ -18,7 +17,7 @@
/// Controller for audio-only playback.
class AudioPlayerController {
- ServiceProvider _services;
+ Incoming _services;
PlayerProxy _player;
@@ -40,7 +39,7 @@
double _deferredNormalizedSeek;
/// Constructs a AudioPlayerController.
- AudioPlayerController(ServiceProvider services) {
+ AudioPlayerController(Incoming services) {
_services = services;
_close(); // Initialize stuff.
}
@@ -57,12 +56,12 @@
}
if (uri.isScheme('FILE')) {
if (headers != null) {
- throw ArgumentError.value(headers,
- 'headers', 'Not valid for FILE URIs.');
+ throw ArgumentError.value(
+ headers, 'headers', 'Not valid for FILE URIs.');
}
} else if (!uri.isScheme('HTTP') && !uri.isScheme('HTTPS')) {
- throw ArgumentError.value(uri,
- 'uri', 'Only HTTP/S and FILE protocols are supported.');
+ throw ArgumentError.value(
+ uri, 'uri', 'Only HTTP/S and FILE protocols are supported.');
}
if (_active) {
@@ -104,7 +103,6 @@
if (_player != null) {
_player.ctrl.close();
- _player.ctrl.onConnectionError = null;
}
_player = PlayerProxy();
@@ -124,22 +122,24 @@
/// Creates a local player.
void _createLocalPlayer(Uri uri, HttpHeaders headers) {
- connectToService(_services, _player.ctrl);
- _player.onStatusChanged = _handleStatusChanged;
+ _services.connectToService(_player);
+ _player.onStatusChanged.listen(_handleStatusChanged);
onMediaPlayerCreated(_player);
- _player.ctrl.onConnectionError = _handleConnectionError;
_setSource(uri, headers);
}
// Sets the source uri on the media player.
void _setSource(Uri uri, HttpHeaders headers) {
if (uri.isScheme('FILE')) {
- _player.setFileSource(
- Channel.fromFile(uri.toFilePath()));
+ _player
+ .setFileSource(Channel.fromFile(uri.toFilePath()))
+ .catchError(_handleConnectionError);
} else {
- _player.setHttpSource(uri.toString(), _convertHeaders(headers));
+ _player
+ .setHttpSource(uri.toString(), _convertHeaders(headers))
+ .catchError(_handleConnectionError);
}
}
@@ -184,8 +184,7 @@
Map<String, String> get metadata => _metadata;
/// Gets the duration of the content.
- Duration get duration =>
- Duration(microseconds: _durationNanoseconds ~/ 1000);
+ Duration get duration => Duration(microseconds: _durationNanoseconds ~/ 1000);
/// Gets current playback progress.
Duration get progress {
@@ -229,10 +228,10 @@
}
if (_ended) {
- _player.seek(0);
+ _player.seek(0).catchError(_handleConnectionError);
}
- _player.play();
+ _player.play().catchError(_handleConnectionError);
}
/// Pauses playback.
@@ -241,7 +240,7 @@
return;
}
- _player.pause();
+ _player.pause().catchError(_handleConnectionError);
}
/// Seeks to a position expressed as a Duration.
@@ -252,7 +251,7 @@
int positionNanoseconds = (position.inMicroseconds * 1000).round();
- _player.seek(positionNanoseconds);
+ _player.seek(positionNanoseconds).catchError(_handleConnectionError);
}
/// Seeks to a position expressed as a normalized value in the range 0.0 to
@@ -289,8 +288,7 @@
if (status.timelineFunction != null) {
tl.TimelineFunction oldTimelineFunction = _timelineFunction;
- _timelineFunction =
- tl.TimelineFunction.fromFidl(status.timelineFunction);
+ _timelineFunction = tl.TimelineFunction.fromFidl(status.timelineFunction);
prepare = oldTimelineFunction != _timelineFunction;
}
@@ -350,7 +348,7 @@
}
/// Called when the connection to the NetMediaPlayer fails.
- void _handleConnectionError() {
+ void _handleConnectionError(Object _) {
_problem = Problem(type: problemConnectionFailed);
if (updateCallback != null) {
diff --git a/public/lib/mediaplayer/dart/timeline.dart b/public/lib/mediaplayer/dart/timeline.dart
index 2732d6f..0defdac 100644
--- a/public/lib/mediaplayer/dart/timeline.dart
+++ b/public/lib/mediaplayer/dart/timeline.dart
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-import 'package:fidl_fuchsia_media/fidl.dart' as media;
+import 'package:fidl_fuchsia_media/fidl_async.dart' as media;
/// Immutable rate of a subject timeline with respect to a reference timeline
/// (subject / reference) expressed as the ratio of two ints.
diff --git a/public/lib/mediaplayer/flutter/media_player_controller.dart b/public/lib/mediaplayer/flutter/media_player_controller.dart
index f9b189a..1db4004 100644
--- a/public/lib/mediaplayer/flutter/media_player_controller.dart
+++ b/public/lib/mediaplayer/flutter/media_player_controller.dart
@@ -5,12 +5,12 @@
import 'dart:async';
import 'dart:io';
-import 'package:fidl_fuchsia_math/fidl.dart' as geom;
-import 'package:fidl_fuchsia_media_playback/fidl.dart';
-import 'package:fidl_fuchsia_sys/fidl.dart';
+import 'package:fidl_fuchsia_math/fidl_async.dart' as geom;
+import 'package:fidl_fuchsia_media_playback/fidl_async.dart';
import 'package:fidl_fuchsia_ui_views/fidl_async.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
+import 'package:fuchsia_services/services.dart';
import 'package:fuchsia_scenic_flutter/child_view_connection.dart'
show ChildViewConnection;
import 'package:lib.mediaplayer.dart/audio_player_controller.dart';
@@ -31,7 +31,7 @@
bool _wasActive;
/// Constructs a MediaPlayerController.
- MediaPlayerController(ServiceProvider services) : super(services) {
+ MediaPlayerController(Incoming services) : super(services) {
updateCallback = _notifyListeners;
_close(); // Initialize stuff.
}
@@ -146,8 +146,8 @@
double ratio =
pixelAspectRatio.width.toDouble() / pixelAspectRatio.height.toDouble();
- _videoSize = Size(
- videoSize.width.toDouble() * ratio, videoSize.height.toDouble());
+ _videoSize =
+ Size(videoSize.width.toDouble() * ratio, videoSize.height.toDouble());
scheduleMicrotask(_notifyListeners);
}