ERM Video fixes

pull/3/head
haroon amjad 1 year ago
parent c4dc3e941d
commit 15c8e80799

@ -91,5 +91,7 @@
<array>
<string>TAG</string>
</array>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>

@ -401,4 +401,15 @@ class Utils {
}
return false;
}
static bool isDate(String input, String format) {
try {
DateTime d = DateFormat(format).parseStrict(input);
//print(d);
return true;
} catch (e) {
//print(e);
return false;
}
}
}

@ -39,6 +39,12 @@ class _ITGAdsScreenState extends State<ITGAdsScreen> {
String? masterID;
int videoDuration = 0;
bool hasTimerEndedBool = false;
final ValueNotifier<bool> hasTimerEnded = ValueNotifier(false);
late CountdownTimerController timerController;
void checkFileType() async {
String? rFile = advertisementData!.viewAttachFileColl!.first.base64String;
String? rFileExt = advertisementData!.viewAttachFileColl!.first.fileName;
@ -56,6 +62,17 @@ class _ITGAdsScreenState extends State<ITGAdsScreen> {
setState(() {});
}
void changeTimer(bool isTimerEnd) {
hasTimerEndedBool = isTimerEnd;
hasTimerEnded.value = !hasTimerEnded.value;
}
void onTimerEnd() {
changeTimer(true);
timerController.disposeTimer();
timerController.dispose();
}
Future processImage(String encodedBytes) async {
try {
Uint8List decodedBytes = base64Decode(encodedBytes.split("base64,").last);
@ -69,18 +86,20 @@ class _ITGAdsScreenState extends State<ITGAdsScreen> {
Future<VideoPlayerController> createVideoPlayer(String encodedBytes) async {
try {
Uint8List decodedBytes = base64Decode(encodedBytes.split("base64,").last);
Directory appDocumentsDirectory = await getApplicationDocumentsDirectory(); // 1
File file = Io.File("${appDocumentsDirectory.path}/myAdsVideo.mp4");
file.writeAsBytesSync(decodedBytes);
VideoPlayerController controller = VideoPlayerController.file(file);
// Uint8List decodedBytes = base64Decode(encodedBytes.split("base64,").last);
// Directory appDocumentsDirectory = await getApplicationDocumentsDirectory(); // 1
// File file = Io.File("${appDocumentsDirectory.path}/myAdsVideo.mp4");
// file.writeAsBytesSync(decodedBytes);
// VideoPlayerController controller = VideoPlayerController.file(file);
VideoPlayerController controller = VideoPlayerController.network(advertisementData!.viewAttachFileColl!.first.base64String!);
await controller.initialize();
await controller.play();
await controller.setVolume(1.0);
await controller.setLooping(false);
return controller;
} catch (e) {
return VideoPlayerController.asset("dataSource");
print(e);
return VideoPlayerController.network("https://apimohemmweb.cloudsolutions.com.sa/ErmAttachment/compressedvideo.mp4");
}
}
@ -107,6 +126,7 @@ class _ITGAdsScreenState extends State<ITGAdsScreen> {
if (advertisementData != null) {
checkFileType();
videoDuration = advertisementData?.durationInSeconds ?? 0;
timerController = CountdownTimerController(endTime: DateTime.now().millisecondsSinceEpoch + 1000 * videoDuration, onEnd: onTimerEnd);
}
return Scaffold(
backgroundColor: Colors.black,
@ -131,24 +151,34 @@ class _ITGAdsScreenState extends State<ITGAdsScreen> {
),
30.height,
CountdownTimer(
controller: timerController,
endTime: DateTime.now().millisecondsSinceEpoch + 1000 * videoDuration,
onEnd: null,
endWidget: "00:00:00".toText14(color: Colors.white, isBold: true),
endWidget: "00:00:00".toText16(color: Colors.white, isBold: true),
textStyle: const TextStyle(color: Colors.white, fontSize: 16, letterSpacing: -0.48, fontWeight: FontWeight.bold),
),
50.height,
Container(padding: const EdgeInsets.all(16), decoration: Utils.containerRadius(MyColors.white, 10), child: const Icon(Icons.thumb_up, color: MyColors.gradiantEndColor))
.onPress(() {
try {
DashboardApiClient().setAdvertisementViewed(masterID!, advertisementData!.advertisementId!).then((value) {
logger.d(value);
Navigator.pop(context);
});
} catch (ex) {
logger.wtf(ex);
Utils.handleException(ex, context, null);
}
}),
ValueListenableBuilder<bool>(
valueListenable: hasTimerEnded,
builder: (context, val, child) {
if (hasTimerEndedBool) {
return Container(
padding: const EdgeInsets.all(16), decoration: Utils.containerRadius(MyColors.white, 10), child: const Icon(Icons.thumb_up, color: MyColors.gradiantEndColor))
.onPress(() {
try {
DashboardApiClient().setAdvertisementViewed(masterID!, advertisementData!.advertisementId!).then((value) {
logger.d(value);
Navigator.pop(context);
});
} catch (ex) {
logger.wtf(ex);
Utils.handleException(ex, context, null);
}
});
} else {
return Container();
}
}),
// DefaultButton(LocaleKeys.home.tr(), () async {
// DashboardApiClient().setAdvertisementViewed(masterID!, advertisementData!.advertisementId!).then((value) {
// logger.d(value);

@ -340,10 +340,15 @@ class _DynamicInputScreenState extends State<DynamicInputScreen> {
idColName = val;
if (getEitDffStructureList![j].fORMATTYPE == "X") {
idColName = Utils.formatDateDefault(idColName!);
// commenting to test
// DateTime date = DateFormat('yyyy-MM-dd').parse(idColName!);
// idColName = DateFormat('yyyy-MM-dd HH:mm:ss').format(date);
idColName = Utils.reverseFormatDate(idColName!);
if (Utils.isDate(Utils.reverseFormatDate(Utils.formatDateNew(idColName)), "yyyy-MM-dd")) {
idColName = Utils.formatStandardDate(Utils.formatStandardDate(Utils.formatDateNew(idColName)));
// idColName = DateFormat('yyyy/MM/dd HH:mm:ss').format(date);
} else if (Utils.isDate(Utils.reverseFormatDate(idColName), "dd-MM-yyyy")) {
// // change date format on 31/05/2023
DateTime date = DateFormat('dd-MM-yyyy').parse(idColName);
idColName = DateFormat('yyyy-MM-dd HH:mm:ss').format(date);
}
}
}

Loading…
Cancel
Save