product recommendations api integration, content bytes

This commit is contained in:
jayesh
2024-05-07 19:27:23 +05:30
parent f0da450dc2
commit 2b564aa57f
16 changed files with 1281 additions and 574 deletions

View File

@@ -1,9 +1,12 @@
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:just_audio/just_audio.dart';
import 'package:traderscircuit/model/ContentBytesModel/content_bytes_categories_model.dart';
import 'package:traderscircuit/model/ContentBytesModel/content_bytes_model.dart';
import '../model/ContentBytesModel/previous_read_user_model.dart';
import '../view/Sidemenu/ContentByte/ContentBytes.dart';
class ContentBytesController extends GetxController {
@@ -11,12 +14,15 @@ class ContentBytesController extends GetxController {
ContentBytesCategoriesModel contentBytesCategoriesModel =
ContentBytesCategoriesModel();
ContentBytesModel contentBytesModel = ContentBytesModel();
PreviousReadOfUserModel previousReadOfUserModel = PreviousReadOfUserModel();
int filterId = 0;
RxBool isApiCalling = true.obs;
RxBool isAudioSeekBarVisible = false.obs;
RxInt indexForAudios = 0.obs;
RxBool titlePlaying = false.obs;
RxList<bool>? titlePlayingList = <bool>[].obs;
bool isAudioInitialize = false;
final progressNotifier = ValueNotifier<ProgressBarState>(
ProgressBarState(
@@ -27,22 +33,21 @@ class ContentBytesController extends GetxController {
);
final buttonNotifier = ValueNotifier<ButtonState>(ButtonState.paused);
late AudioPlayer _audioPlayer;
late AudioPlayer audioPlayer;
@override
void dispose() {
_audioPlayer.stop();
audioPlayer.stop();
super.dispose();
}
void getAudio() => _audioPlayer;
void init(index) async {
_audioPlayer = AudioPlayer();
audioPlayer = AudioPlayer();
isAudioInitialize = true;
indexForAudios.value = index;
try {
await _audioPlayer.setUrl(
//contentBytesModel.data!.audio![index].file ??
'https://ghantalele.com/uploads/files/data-78/38825/Besharam%20Rang_192(Ghantalele.com).mp3');
// await _audioPlayer.setAsset(url);
log(index.toString());
await audioPlayer.setUrl(contentBytesModel.data!.audio![index].link!);
// await audioPlayer.setAsset(url);
} on PlayerException catch (e) {
print("Error code: ${e.code}");
// iOS/macOS: maps to NSError.localizedDescription
@@ -52,7 +57,7 @@ class ContentBytesController extends GetxController {
print("Error message: ${e.message}");
}
//Catching errors during playback (e.g. lost network connection)
_audioPlayer.playbackEventStream.listen((event) {},
audioPlayer.playbackEventStream.listen((event) {},
onError: (Object e, StackTrace st) {
if (e is PlayerException) {
print('Error code: ${e.code}');
@@ -62,7 +67,7 @@ class ContentBytesController extends GetxController {
}
});
_audioPlayer.playerStateStream.listen((playerState) {
audioPlayer.playerStateStream.listen((playerState) {
final isPlaying = playerState.playing;
final processingState = playerState.processingState;
if (!isPlaying) {
@@ -72,12 +77,12 @@ class ContentBytesController extends GetxController {
} else {
_playNextTrack();
// _audioPlayer.seek(Duration.zero);
// _audioPlayer.pause();
// audioPlayer.seek(Duration.zero);
// audioPlayer.pause();
}
});
_audioPlayer.positionStream.listen((position) {
audioPlayer.positionStream.listen((position) {
final oldState = progressNotifier.value;
progressNotifier.value = ProgressBarState(
current: position,
@@ -86,7 +91,7 @@ class ContentBytesController extends GetxController {
);
});
_audioPlayer.bufferedPositionStream.listen((bufferedPosition) {
audioPlayer.bufferedPositionStream.listen((bufferedPosition) {
final oldState = progressNotifier.value;
progressNotifier.value = ProgressBarState(
current: oldState.current,
@@ -95,7 +100,7 @@ class ContentBytesController extends GetxController {
);
});
_audioPlayer.durationStream.listen((totalDuration) {
audioPlayer.durationStream.listen((totalDuration) {
final oldState = progressNotifier.value;
progressNotifier.value = ProgressBarState(
current: oldState.current,
@@ -118,8 +123,8 @@ class ContentBytesController extends GetxController {
init(nextIndex);
play(nextIndex);
} else {
_audioPlayer.seek(Duration.zero);
_audioPlayer.pause();
audioPlayer.seek(Duration.zero);
audioPlayer.pause();
}
}
@@ -138,26 +143,26 @@ class ContentBytesController extends GetxController {
}
void play(index) {
_audioPlayer.play();
audioPlayer.play();
isAudioSeekBarVisible.value = false;
isAudioSeekBarVisible.value = true;
indexForAudios.value = index;
}
void pause() {
_audioPlayer.pause();
audioPlayer.pause();
}
void seek(Duration position) {
_audioPlayer.seek(position);
audioPlayer.seek(position);
}
void stop() {
_audioPlayer.stop();
audioPlayer.stop();
}
bool isPlaying() {
return _audioPlayer.playing;
return audioPlayer.playing;
}
addTitles() {