Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

videoElement.currentTime error #86

Open
Megatronicus opened this issue Sep 18, 2023 · 38 comments
Open

videoElement.currentTime error #86

Megatronicus opened this issue Sep 18, 2023 · 38 comments

Comments

@Megatronicus
Copy link

I'm getting an error for
videoElement.currentTime = thumbnailTimeMs / 1000;

this is the error

lib/Screens/data/screen2.dart:6921:20: Error: The setter 'currentTime' isn't defined for the class 'VideoElement'.

  • 'VideoElement' is from 'package:universal_html/src/html.dart' ('/C:/Users/User/AppData/Local/Pub/Cache/hosted/pub.dev/universal_html-2.2.4/lib/src/html.dart').
    Try correcting the name to the name of an existing setter, or defining a setter or field named 'currentTime'.
    videoElement.currentTime = thumbnailTimeMs / 1000;

This happened after the update to version universal_html: ^2.2.4

Latest version where everything worked universal_html: ^2.2.3

@Megatronicus
Copy link
Author

Downgraded to 2.2.3, still shows the same error, might be something else that changed not the library, solved it with using different code anyway.

@Megatronicus
Copy link
Author

So basically

This doesn't give error in android compile but gives error in web compile for flutter

 videoElement.setAttribute('currentTime', (thumbnailTimeMs / 1000).toString());
        final html.CanvasElement canvas = html.CanvasElement(
       width: videoElement.width,
         height: videoElement.height,
       );

This doesn't give error in web compile but gives error in android compile for flutter

  videoElement.currentTime = thumbnailTimeMs / 1000.0;
 final html.CanvasElement canvas = html.CanvasElement(
    width: videoElement.videoWidth,
    height: videoElement.videoHeight,
  );

I would have to comment out these parts when compiling for either, or possible solution move the whole method to a separate dart file make a new class and call the method like that after checking kIsWeb? Would that be an option for now? As it is now I can't have this code in the same dart file for web and android as it won't compile correctly. Any help is appreciated, thanks.

@Megatronicus
Copy link
Author

Megatronicus commented Oct 23, 2023

I have tried putting the method in a separate class and making a kIsWeb check before calling that class so that maybe when I'm compiling for android/ios it doesn't check that class but it still checks it and I'm still getting the errors when trying to deploy with this specific code to android in flutter (Android Studio)

Code

        videoElement.currentTime = thumbnailTimeMs / 1000.0;
       final html.CanvasElement canvas = html.CanvasElement(
          width: videoElement.videoWidth,
          height: videoElement.videoHeight,
        );

Errors

page.dart:6598:22: Error: The setter 'currentTime' isn't defined for the class 'VideoElement'.
 - 'VideoElement' is from 'package:universal_html/src/html.dart' ('/C:/Users/User/AppData/Local/Pub/Cache/hosted/pub.dev/universal_html-2.2.4/lib/src/html.dart').
Try correcting the name to the name of an existing setter, or defining a setter or field named 'currentTime'.
        videoElement.currentTime = thumbnailTimeMs / 1000.0;
                     ^^^^^^^^^^^
page.dart:6605:31: Error: The getter 'videoWidth' isn't defined for the class 'VideoElement'.
 - 'VideoElement' is from 'package:universal_html/src/html.dart' ('/C:/Users/User/AppData/Local/Pub/Cache/hosted/pub.dev/universal_html-2.2.4/lib/src/html.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'videoWidth'.
          width: videoElement.videoWidth,
                              ^^^^^^^^^^
page.dart:6606:32: Error: The getter 'videoHeight' isn't defined for the class 'VideoElement'.
 - 'VideoElement' is from 'package:universal_html/src/html.dart' ('/C:/Users/User/AppData/Local/Pub/Cache/hosted/pub.dev/universal_html-2.2.4/lib/src/html.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'videoHeight'.
          height: videoElement.videoHeight,
                               ^^^^^^^^^^^

Can you please correct this, or should I download the universal_html, import all the classes instead of using pubspec and then change things on my own?

@Megatronicus
Copy link
Author

Any help would be appreciated

@Megatronicus
Copy link
Author

Hello? Any help would be appreciated.

@Megatronicus
Copy link
Author

Hello? Any help would be appreciated with this.

@Megatronicus
Copy link
Author

It's almost going to be 2 months since I asked a question here, can someone please respond?

@Megatronicus
Copy link
Author

Please can you help me?

@Megatronicus
Copy link
Author

Guys, please can someone here help me with this?

@Megatronicus
Copy link
Author

Can someone please help me with this?

@Megatronicus
Copy link
Author

Please guys, anyone?

@Megatronicus
Copy link
Author

Please can someone please help me with this?

@Megatronicus
Copy link
Author

Hello, guys, can someone please help me with this?!

@Megatronicus
Copy link
Author

Any help would really be appreciated, can you please answer and help me with this?

@Megatronicus
Copy link
Author

Hello, guys, any help would be appreciated

@Megatronicus
Copy link
Author

Hi guys, once again, please help

@Megatronicus
Copy link
Author

Guys I have been waiting since Sept 18, two months and 4 days for a response. Can you guys please help me?

@Megatronicus
Copy link
Author

Please can you please answer guys?

@Megatronicus
Copy link
Author

Guys, seriously, it's been like 2 and a half months by now, can you please answer?!??!?!?!!

@Megatronicus
Copy link
Author

Please can you please respond?

@Megatronicus
Copy link
Author

Can you please respond?

@Megatronicus
Copy link
Author

Megatronicus commented Dec 2, 2023

Can I please get an answer. I've copied all the classes and pubspec into my app, need to modify it, maybe it will work like that. Removed universal_html from pubspec of the app. Next step reference all the classes internally, maybe this will cause more problems than I already have

@Megatronicus
Copy link
Author

Please, can you answer

@Megatronicus
Copy link
Author

Since it's not a library I can't access "import 'dart:indexed_db';"
I've tried it all kinds of ways, also copying over 100 classes to my app just to change 2 lines of code so I can use universal_html is just overkill. Can you guys please answer, it should be a half a minute of work for you to change the code so it works correctly. Please answer.

@Megatronicus
Copy link
Author

Can you guys please answer?

@Megatronicus
Copy link
Author

Please, can you answer?

@Megatronicus
Copy link
Author

Please guys come on can you please answer and solve this?

@Megatronicus
Copy link
Author

I really need help with this, come on guys

@Megatronicus
Copy link
Author

Is there a way to solve this quickly, please?

@Megatronicus
Copy link
Author

There's gotta be a way from your side to just update that piece of the code. There's over a 100 classes in universal_html, it doesn't make a lot of sense copying all of that, I already tried it anyway but can't import indexed_db because the project is not a library and there were other errors connected probably to that.

@Megatronicus
Copy link
Author

Please can you please answer?

@Megatronicus
Copy link
Author

So, it's now been 3 and a half months since I asked this question. Please, can you please answer?!

@MyTechAgent
Copy link

Yep add me to the count too.

@NotTsunami
Copy link

@Megatronicus 32 comments is actually psycopath behavior. Spamming the author's other repos is a good way to get yourself banned from commenting as well. Most people that contribute to these libraries do so on their own free time, and are in no way obligated to answer your question. If you needed help that bad, you could have even asked ChatGPT instead of begging 32 times.

Here is the answer you are looking for: currentTime is indeed not a member of the VideoElement class of universal_html, as the error suggests. currentTime is a member of the VideoElement class of the actual html package, though. That's just a limitation of this library.

https://github.com/dint-dev/universal_html/blob/master/lib/src/html/dom/element_subclasses.dart#L3339

@NotTsunami
Copy link

I am unsure of how you are actually implementing things, but my suggestion is using a shim, sort of like how you see here with dart_ui.dart, dart_ui_real.dart and dart_ui_fake.dart: https://github.com/flutter/packages/tree/camera_web-v0.3.1%2B2/packages/camera/camera_web/lib/src/shims

In dart_ui_fake.dart, you'll see they were able to use the dart:html package directly in a cross-platform way as the package is only actually imported and used on web. This is what Flutter themselves used to do when they needed to reference web-only APIs in a cross-platform project.

@Megatronicus
Copy link
Author

@NotTsunami

Halleluiah!!!! =D
Actually, I think it's psychopath not to answer for 4 months, but who am I to judge, I tried reaching you everywhere as a last resort after multiple attempts here. I understand you're not obligated to answer, but in the good spirit of flutter code development it would be commendable so thank you for finally answering even though you didn't have to. =) Also, chatGPT didn't provide a valid solution multiple, multiple and multiple times that I asked

This last answer you posted, I've seen that elsewhere but didn't really use it.

Do you possibly have another simpler example to teach the concept? I have this like I explained:

This doesn't give error in android compile but gives error in web compile for flutter

videoElement.setAttribute('currentTime', (thumbnailTimeMs / 1000).toString());
final html.CanvasElement canvas = html.CanvasElement(
width: videoElement.width,
height: videoElement.height,
);
This doesn't give error in web compile but gives error in android compile for flutter

videoElement.currentTime = thumbnailTimeMs / 1000.0;
final html.CanvasElement canvas = html.CanvasElement(
width: videoElement.videoWidth,
height: videoElement.videoHeight,
);

How would you organize things so you wouldn't have to comment out one and uncomment the other every time you change from web to android and android to web? I see you've provided the example where multiple classes are just redirecting with imports but I've tried something similar to this and it didn't work.

@NotTsunami
Copy link

Halleluiah!!!! =D Actually, I think it's psychopath not to answer for 4 months, but who am I to judge, I tried reaching you everywhere as a last resort after multiple attempts here

I'm also not the person you were looking for - just someone else that works with Flutter.

This last answer you posted, I've seen that elsewhere but didn't really use it.

The magic of that solution is in the dart_ui.dart file, specifically this line:

export 'dart_ui_fake.dart' if (dart.library.html) 'dart_ui_real.dart';

Flutter doesn't support conditional imports out of the box (meaning you can't just wrap an import in any random condition) - but this sort of import is allowed. I use Flutter currently for a cross-platform (desktop and web) project and I've run into an issue of where I need different code on each platform but importing dart:html gives you the warning to only use on web. I'll break this down with the way I've implemented this before. Imagine you had the following setup:

my_class.dart

import 'desktop.dart' if (dart.library.html) 'web.dart' as my_class;

class MyClass {
    void startClient() {
        my_class.start();
    }
}

desktop.dart

void start() {
    ...some desktop specific code...
}

web.dart

void start() {
    ...some web specific code...
}

With this setup, you can call startClient() on an instance of MyClass anywhere in your code and your code will properly execute the correct start() function for the platform. I haven't tested with your example, but I think this should work for your example.

@Megatronicus
Copy link
Author

Halleluiah!!!! =D Actually, I think it's psychopath not to answer for 4 months, but who am I to judge, I tried reaching you everywhere as a last resort after multiple attempts here

I'm also not the person you were looking for - just someone else that works with Flutter.

This last answer you posted, I've seen that elsewhere but didn't really use it.

The magic of that solution is in the dart_ui.dart file, specifically this line:

export 'dart_ui_fake.dart' if (dart.library.html) 'dart_ui_real.dart';

Flutter doesn't support conditional imports out of the box (meaning you can't just wrap an import in any random condition) - but this sort of import is allowed. I use Flutter currently for a cross-platform (desktop and web) project and I've run into an issue of where I need different code on each platform but importing dart:html gives you the warning to only use on web. I'll break this down with the way I've implemented this before. Imagine you had the following setup:

my_class.dart

import 'desktop.dart' if (dart.library.html) 'web.dart' as my_class;

class MyClass {
    void startClient() {
        my_class.start();
    }
}

desktop.dart

void start() {
    ...some desktop specific code...
}

web.dart

void start() {
    ...some web specific code...
}

With this setup, you can call startClient() on an instance of MyClass anywhere in your code and your code will properly execute the correct start() function for the platform. I haven't tested with your example, but I think this should work for your example.

Thank you for answering, I will try this in a couple of days, will get back to you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants