WIP audioplayer view support but not supported, need project upgrade
This commit is contained in:
parent
eddc4005ae
commit
412746e39a
@ -1,105 +1,212 @@
|
||||
/*import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:audioplayers/audioplayers.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:manager_app/app_context.dart';
|
||||
import 'package:manager_app/constants.dart';
|
||||
import 'package:managerapi/api.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import 'loading_common.dart';
|
||||
|
||||
class AudioPlayerContainer extends StatefulWidget {
|
||||
const AudioPlayerContainer({Key? key}) : super(key: key);
|
||||
const AudioPlayerContainer({Key key, this.resourceDTO, this.isAuto}) : super(key: key);
|
||||
|
||||
final ResourceDTO resourceDTO;
|
||||
final bool isAuto;
|
||||
|
||||
@override
|
||||
_AudioPlayerContainerState createState() => _AudioPlayerContainerState();
|
||||
State<AudioPlayerContainer> createState() => _AudioPlayerContainerState();
|
||||
}
|
||||
|
||||
class _AudioPlayerContainerState extends State<AudioPlayerContainer> {
|
||||
List<AudioPlayer> players =
|
||||
List.generate(4, (_) => AudioPlayer()..setReleaseMode(ReleaseMode.stop));
|
||||
int selectedPlayerIdx = 0;
|
||||
|
||||
AudioPlayer get selectedPlayer => players[selectedPlayerIdx];
|
||||
List<StreamSubscription> streams = [];
|
||||
AudioPlayer player = AudioPlayer();
|
||||
Uint8List audiobytes;
|
||||
bool isplaying = false;
|
||||
bool audioplayed = false;
|
||||
int currentpos = 0;
|
||||
int maxduration = 100;
|
||||
String currentpostlabel = "00:00";
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
//Uint8List base64String = base64Decode(audiobytes); // LOAD DATA
|
||||
|
||||
/*Future.delayed(Duration.zero, () async {
|
||||
player.onDurationChanged.listen((Duration d) { //get the duration of audio
|
||||
maxduration = d.inSeconds;
|
||||
setState(() {
|
||||
});
|
||||
});
|
||||
|
||||
player.onAudioPositionChanged.listen((Duration p){
|
||||
currentpos = p.inMilliseconds; //get the current position of playing audio
|
||||
|
||||
//generating the duration label
|
||||
int shours = Duration(milliseconds:currentpos).inHours;
|
||||
int sminutes = Duration(milliseconds:currentpos).inMinutes;
|
||||
int sseconds = Duration(milliseconds:currentpos).inSeconds;
|
||||
|
||||
int rminutes = sminutes - (shours * 60);
|
||||
int rseconds = sseconds - (sminutes * 60 + shours * 60 * 60);
|
||||
|
||||
String minutesToShow = rminutes < 10 ? '0$rminutes': rminutes.toString();
|
||||
String secondsToShow = rseconds < 10 ? '0$rseconds': rseconds.toString();
|
||||
|
||||
currentpostlabel = "$minutesToShow:$secondsToShow";
|
||||
|
||||
setState(() {
|
||||
//refresh the UI
|
||||
});
|
||||
});
|
||||
|
||||
if(widget.isAuto) {
|
||||
player.playBytes(audiobytes);
|
||||
setState(() {
|
||||
isplaying = true;
|
||||
audioplayed = true;
|
||||
});
|
||||
}
|
||||
});*/
|
||||
super.initState();
|
||||
players.asMap().forEach((index, player) {
|
||||
streams.add(
|
||||
player.onPlayerComplete.listen(
|
||||
(it) => toast(
|
||||
'Player complete!',
|
||||
textKey: Key('toast-player-complete-$index'),
|
||||
),
|
||||
),
|
||||
);
|
||||
streams.add(
|
||||
player.onSeekComplete.listen(
|
||||
(it) => toast(
|
||||
'Seek complete!',
|
||||
textKey: Key('toast-seek-complete-$index'),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
streams.forEach((it) => it.cancel());
|
||||
/*player.stop();
|
||||
player.dispose();*/
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('audioplayers example'),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Center(
|
||||
child: Tgl(
|
||||
options: ['P1', 'P2', 'P3', 'P4']
|
||||
.asMap()
|
||||
.map((key, value) => MapEntry('player-$key', value)),
|
||||
selected: selectedPlayerIdx,
|
||||
onChange: (v) => setState(() => selectedPlayerIdx = v),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Tabs(
|
||||
tabs: [
|
||||
TabData(
|
||||
key: 'sourcesTab',
|
||||
label: 'Src',
|
||||
content: SourcesTab(player: selectedPlayer),
|
||||
),
|
||||
TabData(
|
||||
key: 'controlsTab',
|
||||
label: 'Ctrl',
|
||||
content: ControlsTab(player: selectedPlayer),
|
||||
),
|
||||
TabData(
|
||||
key: 'streamsTab',
|
||||
label: 'Stream',
|
||||
content: StreamsTab(player: selectedPlayer),
|
||||
),
|
||||
TabData(
|
||||
key: 'audioContextTab',
|
||||
label: 'Ctx',
|
||||
content: AudioContextTab(player: selectedPlayer),
|
||||
),
|
||||
TabData(
|
||||
key: 'loggerTab',
|
||||
label: 'Log',
|
||||
content: const LoggerTab(),
|
||||
final appContext = Provider.of<AppContext>(context);
|
||||
Size size = MediaQuery.of(context).size;
|
||||
|
||||
return FutureBuilder(
|
||||
future: getAudio(widget.resourceDTO.id, appContext),
|
||||
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
print("DOOOONE");
|
||||
if(snapshot.data != null) {
|
||||
print("snapshot.data");
|
||||
print(snapshot.data);
|
||||
//this.player.playBytes(audiobytes);
|
||||
}
|
||||
|
||||
return Container(
|
||||
child: Column(
|
||||
children: [
|
||||
|
||||
Container(
|
||||
child: Text(currentpostlabel, style: TextStyle(fontSize: 25),),
|
||||
),
|
||||
|
||||
Container(
|
||||
child: Wrap(
|
||||
spacing: 10,
|
||||
children: [
|
||||
ElevatedButton.icon(
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: kPrimaryColor, // Background color
|
||||
),
|
||||
onPressed: () async {
|
||||
print(isplaying);
|
||||
print(audioplayed);
|
||||
if(!isplaying && !audioplayed){
|
||||
player.playBytes(audiobytes);
|
||||
//player.playBytes(bytes)
|
||||
setState(() {
|
||||
isplaying = true;
|
||||
audioplayed = true;
|
||||
});
|
||||
}else if(audioplayed && !isplaying){
|
||||
player.resume();
|
||||
setState(() {
|
||||
isplaying = true;
|
||||
audioplayed = true;
|
||||
});
|
||||
}else{
|
||||
player.pause();
|
||||
setState(() {
|
||||
isplaying = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
icon: Icon(isplaying?Icons.pause:Icons.play_arrow),
|
||||
label:Text(isplaying?"Pause":"Play")
|
||||
),
|
||||
|
||||
ElevatedButton.icon(
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: kPrimaryColor, // Background color
|
||||
),
|
||||
onPressed: () async {
|
||||
/*player.stop();
|
||||
setState(() {
|
||||
isplaying = false;
|
||||
audioplayed = false;
|
||||
currentpostlabel = "00:00";
|
||||
});*/
|
||||
},
|
||||
icon: Icon(Icons.stop),
|
||||
label:Text("Stop")
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}else if (snapshot.connectionState == ConnectionState.none) {
|
||||
return Text("No data");
|
||||
} else {
|
||||
return Center(
|
||||
child: Container(
|
||||
height: size.height * 0.2,
|
||||
child: LoadingCommon()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
Future<Uint8List> getAudio(String resourceId, AppContext appContext) async {
|
||||
try {
|
||||
var url = "https://api.mymuseum.be/api/Resource/"+resourceId; // TO TEST TODO UPDATE ROUTE
|
||||
print("DOWNLOAD AUDDDDIOOOOO ------------");
|
||||
print(url);
|
||||
//HttpClient client2 = HttpClient();
|
||||
print("before.. hmmm? ");
|
||||
var _downloadData = <int>[];
|
||||
|
||||
print("before.. ? ");
|
||||
|
||||
/*var test = await http.get(Uri.parse(url));
|
||||
print("test");
|
||||
print(test);*/
|
||||
|
||||
var test2 = await http.readBytes(Uri.parse(url));
|
||||
print("test2");
|
||||
print(test2);
|
||||
|
||||
//final HttpClientRequest request = await client2.getUrl(url);
|
||||
print("RESPONSE");
|
||||
/*HttpClientResponse response = await request.close();
|
||||
await for(dynamic d in response) { _downloadData.addAll(d); }
|
||||
print("AFTER");*/
|
||||
final base64Str = base64.encode(test2);
|
||||
Uint8List base64String = base64Decode(base64Str); // LOAD DATA
|
||||
return base64String;
|
||||
} catch (e) {
|
||||
print(e);
|
||||
print("IN CATCH");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
import 'package:manager_app/Components/audio_player.dart';
|
||||
import 'package:manager_app/app_context.dart';
|
||||
import 'package:managerapi/api.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
getImageForResource(dynamic resourceDTO, AppContext appContext) {
|
||||
getElementForResource(dynamic resourceDTO, AppContext appContext) {
|
||||
switch(resourceDTO.type) {
|
||||
case ResourceType.image:
|
||||
return Image.network(
|
||||
@ -17,6 +18,7 @@ getImageForResource(dynamic resourceDTO, AppContext appContext) {
|
||||
);
|
||||
break;
|
||||
case ResourceType.audio:
|
||||
//return AudioPlayerContainer(resourceDTO: resourceDTO, isAuto: true);
|
||||
return Text("Fichier audio - aucune visualisation possible");
|
||||
break;
|
||||
case ResourceType.video:
|
||||
@ -49,24 +49,28 @@ class _ResourcesScreenState extends State<ResourcesScreen> {
|
||||
if(snapshot.data != null) {
|
||||
var tempOutput = new List<ResourceDTO>.from(snapshot.data);
|
||||
// tempOutput.add(ResourceDTO(id: null));
|
||||
return ResourceBodyGrid(resources: tempOutput, resourceTypesIn: widget.isImage ? resource_types.where((rt) => rt.type == ResourceType.image || rt.type == ResourceType.imageUrl).map((rt) => rt.type).toList() : widget.resourceTypes, isAddButton: widget.isAddButton, onSelect: (value) async {
|
||||
if (widget.onGetResult == null) {
|
||||
// Main screen
|
||||
if (value.id == null) {
|
||||
var result = await showNewResource(appContext, context);
|
||||
if (result != null)
|
||||
{
|
||||
await create(result[0], result[1], result[2], appContext, context);
|
||||
setState(() {}); // For refresh
|
||||
return ResourceBodyGrid(
|
||||
resources: tempOutput,
|
||||
resourceTypesIn: widget.isImage ? resource_types.where((rt) => rt.type == ResourceType.image || rt.type == ResourceType.imageUrl).map((rt) => rt.type).toList() : widget.resourceTypes,
|
||||
isAddButton: widget.isAddButton,
|
||||
onSelect: (value) async {
|
||||
if (widget.onGetResult == null) {
|
||||
// Main screen
|
||||
if (value.id == null) {
|
||||
var result = await showNewResource(appContext, context);
|
||||
if (result != null)
|
||||
{
|
||||
await create(result[0], result[1], result[2], appContext, context);
|
||||
setState(() {}); // For refresh
|
||||
}
|
||||
} else {
|
||||
showResource(value, appContext, context, size);
|
||||
}
|
||||
} else {
|
||||
showResource(value, appContext, context, size);
|
||||
// Result for select modal
|
||||
widget.onGetResult(value);
|
||||
}
|
||||
} else {
|
||||
// Result for select modal
|
||||
widget.onGetResult(value);
|
||||
}
|
||||
},);//bodyGrid(tempOutput, size, appContext);
|
||||
});//bodyGrid(tempOutput, size, appContext);
|
||||
} else {
|
||||
return Text("No data");
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ import 'package:manager_app/app_context.dart';
|
||||
import 'package:manager_app/constants.dart';
|
||||
import 'package:managerapi/api.dart';
|
||||
|
||||
import 'fetch_image_for_resource.dart';
|
||||
import 'get_element_for_resource.dart';
|
||||
|
||||
void showResource(ResourceDTO resourceDTO, AppContext appContext, BuildContext context, Size size) {
|
||||
showDialog(
|
||||
@ -34,7 +34,7 @@ void showResource(ResourceDTO resourceDTO, AppContext appContext, BuildContext c
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: getImageForResource(resourceDTO, appContext),
|
||||
child: getElementForResource(resourceDTO, appContext),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user