near final
This commit is contained in:
35
lib/utils/OrdinanceSurveyUtils.dart
Normal file
35
lib/utils/OrdinanceSurveyUtils.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
import 'dart:math' as math;
|
||||
import 'package:proj4dart/proj4dart.dart' as proj4;
|
||||
import 'package:vector_math/vector_math.dart';
|
||||
|
||||
|
||||
class OSGrid {
|
||||
|
||||
static List<double> toLatLong(double northing, double easting) {
|
||||
|
||||
final sourceProjection = proj4.Projection.parse('+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 '
|
||||
'+x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs'); // British National Grid
|
||||
final destinationProjection = proj4.Projection.WGS84;// WGS84
|
||||
|
||||
final point = proj4.Point(x: easting, y: northing);
|
||||
final transformedPoint = sourceProjection.transform(destinationProjection, point);
|
||||
|
||||
|
||||
|
||||
return [transformedPoint.y, transformedPoint.x];
|
||||
}
|
||||
|
||||
static Vector2 toNorthingEasting(double latitude, double longitude) {
|
||||
|
||||
final sourceProjection = proj4.Projection.WGS84;// WGS84
|
||||
final destinationProjection = proj4.Projection.parse('+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 '
|
||||
'+x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs'); // British National Grid
|
||||
|
||||
final point = proj4.Point(x: longitude, y: latitude);
|
||||
final transformedPoint = sourceProjection.transform(destinationProjection, point);
|
||||
|
||||
return Vector2(transformedPoint.x, transformedPoint.y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,11 @@ import 'package:audioplayers/audioplayers.dart' as audioplayers;
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:just_audio/just_audio.dart' as justaudio;
|
||||
|
||||
enum AudioWrapper_Mode {
|
||||
Web,
|
||||
Mobile
|
||||
}
|
||||
|
||||
enum AudioWrapper_State {
|
||||
Playing,
|
||||
NotPlaying
|
||||
@@ -13,6 +18,16 @@ class AudioWrapper {
|
||||
audioplayers.AudioPlayer _audioPlayer_AudioPlayer = audioplayers.AudioPlayer();
|
||||
justaudio.AudioPlayer _justAudio_AudioPlayer = justaudio.AudioPlayer();
|
||||
|
||||
AudioWrapper_Mode mode = kIsWeb ? AudioWrapper_Mode.Web : AudioWrapper_Mode.Mobile;
|
||||
|
||||
AudioWrapper() {
|
||||
// mode = AudioWrapper_Mode.Web;
|
||||
|
||||
print("AudioWrapper mode: $mode");
|
||||
|
||||
// mode = AudioWrapper_Mode.Mobile;
|
||||
}
|
||||
|
||||
justaudio.AudioSource _convertSource_JustAudio(AudioWrapperSource source){
|
||||
if (source is AudioWrapperByteSource){
|
||||
return _ByteSource(source.bytes);
|
||||
@@ -33,45 +48,94 @@ class AudioWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
Future<Duration?> play(AudioWrapperSource source) async {
|
||||
|
||||
Duration? duration;
|
||||
|
||||
if (kIsWeb) {
|
||||
Future<void> loadSource(AudioWrapperSource source) async {
|
||||
if (mode == AudioWrapper_Mode.Web) {
|
||||
// Use just_audio
|
||||
|
||||
justaudio.AudioSource audioSource = _convertSource_JustAudio(source);
|
||||
|
||||
duration = await _justAudio_AudioPlayer.setAudioSource(audioSource);
|
||||
await _justAudio_AudioPlayer.setAudioSource(audioSource);
|
||||
|
||||
_justAudio_AudioPlayer.play();
|
||||
|
||||
|
||||
} else {
|
||||
} else if (mode == AudioWrapper_Mode.Mobile) {
|
||||
// Use audioplayers
|
||||
|
||||
audioplayers.Source audioSource = _convertSource_AudioPlayers(source);
|
||||
|
||||
await _audioPlayer_AudioPlayer.play(audioSource);
|
||||
await _audioPlayer_AudioPlayer.setSource(audioSource);
|
||||
// await _audioPlayer_AudioPlayer.play(audioSource);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Duration?> getDuration() async {
|
||||
if (mode == AudioWrapper_Mode.Web) {
|
||||
return _justAudio_AudioPlayer.duration;
|
||||
} else if (mode == AudioWrapper_Mode.Mobile) {
|
||||
return await _audioPlayer_AudioPlayer.getDuration();
|
||||
}
|
||||
}
|
||||
|
||||
Future<Duration?> play() async {
|
||||
|
||||
Duration? duration;
|
||||
|
||||
if (mode == AudioWrapper_Mode.Web) {
|
||||
_justAudio_AudioPlayer.play();
|
||||
duration = _justAudio_AudioPlayer.duration;
|
||||
} else if (mode == AudioWrapper_Mode.Mobile) {
|
||||
_audioPlayer_AudioPlayer.resume();
|
||||
duration = await _audioPlayer_AudioPlayer.getDuration();
|
||||
}
|
||||
|
||||
|
||||
|
||||
return duration;
|
||||
}
|
||||
|
||||
// Future<Duration?> play(AudioWrapperSource source) async {
|
||||
//
|
||||
// Duration? duration;
|
||||
//
|
||||
// if (mode == AudioWrapper_Mode.Web) {
|
||||
// // Use just_audio
|
||||
//
|
||||
// justaudio.AudioSource audioSource = _convertSource_JustAudio(source);
|
||||
//
|
||||
// duration = await _justAudio_AudioPlayer.setAudioSource(audioSource);
|
||||
//
|
||||
// _justAudio_AudioPlayer.play();
|
||||
//
|
||||
//
|
||||
// } else if (mode == AudioWrapper_Mode.Mobile) {
|
||||
// // Use audioplayers
|
||||
//
|
||||
// audioplayers.Source audioSource = _convertSource_AudioPlayers(source);
|
||||
//
|
||||
// await _audioPlayer_AudioPlayer.play(audioSource);
|
||||
//
|
||||
// duration = await _audioPlayer_AudioPlayer.getDuration();
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// return duration;
|
||||
// }
|
||||
|
||||
void stop(){
|
||||
if (kIsWeb) {
|
||||
if (mode == AudioWrapper_Mode.Web) {
|
||||
_justAudio_AudioPlayer.stop();
|
||||
} else {
|
||||
try {
|
||||
_justAudio_AudioPlayer.dispose();
|
||||
} catch (e) {}
|
||||
_justAudio_AudioPlayer = justaudio.AudioPlayer();
|
||||
} else if (mode == AudioWrapper_Mode.Mobile) {
|
||||
_audioPlayer_AudioPlayer.stop();
|
||||
try {
|
||||
_audioPlayer_AudioPlayer.dispose();
|
||||
} catch (e) {}
|
||||
_audioPlayer_AudioPlayer = audioplayers.AudioPlayer();
|
||||
}
|
||||
}
|
||||
|
||||
AudioWrapper_State get state {
|
||||
if (kIsWeb) {
|
||||
if (mode == AudioWrapper_Mode.Web) {
|
||||
if (_justAudio_AudioPlayer.playing){
|
||||
return AudioWrapper_State.Playing;
|
||||
} else {
|
||||
|
||||
@@ -11,7 +11,7 @@ class ListenerReceipt<T> {
|
||||
}
|
||||
|
||||
class EventDelegate<T> {
|
||||
final List<ListenerReceipt<T>> _receipts = [];
|
||||
final List<ListenerReceipt<T>> _receipts = [];
|
||||
|
||||
ListenerReceipt<T> addListener(Function(T) listener) {
|
||||
final receipt = ListenerReceipt(listener);
|
||||
@@ -26,14 +26,16 @@ class EventDelegate<T> {
|
||||
|
||||
void trigger(T event) {
|
||||
print("triggering event");
|
||||
for (var receipt in _receipts) {
|
||||
print("triggering listener");
|
||||
try {
|
||||
receipt.listener(event);
|
||||
} catch (e) {
|
||||
print("Error in listener: $e");
|
||||
removeListener(receipt);
|
||||
try {
|
||||
for (var receipt in _receipts) {
|
||||
print("triggering listener");
|
||||
try {
|
||||
receipt.listener(event);
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print("Error in trigger: $e");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user