Visualizer implementation for Android.
This commit is contained in:
parent
602dc44029
commit
1fecd5ac1f
13 changed files with 457 additions and 43 deletions
|
@ -1,4 +1,5 @@
|
|||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:meta/meta.dart' show required;
|
||||
|
@ -68,6 +69,17 @@ abstract class AudioPlayerPlatform {
|
|||
'playbackEventMessageStream has not been implemented.');
|
||||
}
|
||||
|
||||
/// A stream of visualizer waveform data.
|
||||
Stream<Uint8List> get visualizerWaveformStream {
|
||||
throw UnimplementedError(
|
||||
'visualizerWaveformStream has not been implemented.');
|
||||
}
|
||||
|
||||
/// A stream of visualizer fft data.
|
||||
Stream<Uint8List> get visualizerFftStream {
|
||||
throw UnimplementedError('visualizerFftStream has not been implemented.');
|
||||
}
|
||||
|
||||
/// Loads an audio source.
|
||||
Future<LoadResponse> load(LoadRequest request) {
|
||||
throw UnimplementedError("load() has not been implemented.");
|
||||
|
@ -157,6 +169,17 @@ abstract class AudioPlayerPlatform {
|
|||
ConcatenatingMoveRequest request) {
|
||||
throw UnimplementedError("concatenatingMove() has not been implemented.");
|
||||
}
|
||||
|
||||
/// Starts the visualizer.
|
||||
Future<StartVisualizerResponse> startVisualizer(
|
||||
StartVisualizerRequest request) {
|
||||
throw UnimplementedError("startVisualizer() has not been implemented.");
|
||||
}
|
||||
|
||||
/// Stops the visualizer.
|
||||
Future<StopVisualizerResponse> stopVisualizer(StopVisualizerRequest request) {
|
||||
throw UnimplementedError("stopVisualizer() has not been implemented.");
|
||||
}
|
||||
}
|
||||
|
||||
/// A playback event communicated from the platform implementation to the
|
||||
|
@ -624,6 +647,53 @@ class ConcatenatingMoveResponse {
|
|||
ConcatenatingMoveResponse();
|
||||
}
|
||||
|
||||
/// Information communicated to the platform implementation when starting the
|
||||
/// visualizer.
|
||||
class StartVisualizerRequest {
|
||||
final bool enableWaveform;
|
||||
final bool enableFft;
|
||||
final int captureRate;
|
||||
final int captureSize;
|
||||
|
||||
StartVisualizerRequest({
|
||||
@required this.enableWaveform,
|
||||
@required this.enableFft,
|
||||
@required this.captureRate,
|
||||
@required this.captureSize,
|
||||
});
|
||||
|
||||
Map<dynamic, dynamic> toMap() => {
|
||||
'enableWaveform': enableWaveform,
|
||||
'enableFft': enableFft,
|
||||
'captureRate': captureRate,
|
||||
'captureSize': captureSize,
|
||||
};
|
||||
}
|
||||
|
||||
/// Information returned by the platform implementation after starting the
|
||||
/// visualizer.
|
||||
class StartVisualizerResponse {
|
||||
final int samplingRate;
|
||||
|
||||
StartVisualizerResponse({@required this.samplingRate});
|
||||
|
||||
static StartVisualizerResponse fromMap(Map<dynamic, dynamic> map) =>
|
||||
StartVisualizerResponse(samplingRate: map['samplingRate']);
|
||||
}
|
||||
|
||||
/// Information communicated to the platform implementation when stopping the
|
||||
/// visualizer.
|
||||
class StopVisualizerRequest {
|
||||
Map<dynamic, dynamic> toMap() => {};
|
||||
}
|
||||
|
||||
/// Information returned by the platform implementation after stopping the
|
||||
/// visualizer.
|
||||
class StopVisualizerResponse {
|
||||
static StopVisualizerResponse fromMap(Map<dynamic, dynamic> map) =>
|
||||
StopVisualizerResponse();
|
||||
}
|
||||
|
||||
/// Information about an audio source to be communicated with the platform
|
||||
/// implementation.
|
||||
abstract class AudioSourceMessage {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
|
@ -36,6 +37,18 @@ class MethodChannelAudioPlayer extends AudioPlayerPlatform {
|
|||
.receiveBroadcastStream()
|
||||
.map((map) => PlaybackEventMessage.fromMap(map));
|
||||
|
||||
@override
|
||||
Stream<Uint8List> get visualizerWaveformStream =>
|
||||
EventChannel('com.ryanheise.just_audio.waveform_events.$id')
|
||||
.receiveBroadcastStream()
|
||||
.cast<Uint8List>();
|
||||
|
||||
@override
|
||||
Stream<Uint8List> get visualizerFftStream =>
|
||||
EventChannel('com.ryanheise.just_audio.fft_events.$id')
|
||||
.receiveBroadcastStream()
|
||||
.cast<Uint8List>();
|
||||
|
||||
@override
|
||||
Future<LoadResponse> load(LoadRequest request) async {
|
||||
return LoadResponse.fromMap(
|
||||
|
@ -134,4 +147,18 @@ class MethodChannelAudioPlayer extends AudioPlayerPlatform {
|
|||
return ConcatenatingMoveResponse.fromMap(
|
||||
await _channel.invokeMethod('concatenatingMove', request?.toMap()));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<StartVisualizerResponse> startVisualizer(
|
||||
StartVisualizerRequest request) async {
|
||||
return StartVisualizerResponse.fromMap(
|
||||
await _channel.invokeMethod('startVisualizer', request?.toMap()));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<StopVisualizerResponse> stopVisualizer(
|
||||
StopVisualizerRequest request) async {
|
||||
return StopVisualizerResponse.fromMap(
|
||||
await _channel.invokeMethod('stopVisualizer', request?.toMap()));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue