Giter VIP home page Giter VIP logo

Comments (11)

dmrschmidt avatar dmrschmidt commented on May 12, 2024 1

Awesome, glad to know it works now :)

As an FYI, I've used the issue you ran into as an opportunity to re-visit the SwiftUI APIs and have changed them now to not require a Binding. The example project now also uses an optional URL in its @State, so you can see how i would solve your problem now.

As this is a breaking API change, it's released as 11.0.0, so you'd need to make sure you update your package dependency to next major 11. Of course feel free to keep using your own implementation of the view part.

If you do decide to use the provided views from 11.0.0 again, don't forget to add import DSWaveformImageViews.

from dswaveformimage.

dmrschmidt avatar dmrschmidt commented on May 12, 2024

Hey @CacereLucas,

I’m afraid I need a little more information to help here.

Why can’t you use those URLs?
What is the observed behavior? Are there any error messages? What means “relative URL”? Relative to where / what? Could you share an example url here?

I assume you’re playing these audio files? So AVPlayer plays them without issue?

With a little more info we should be able to figure out what the problem is :)

from dswaveformimage.

CacereLucas avatar CacereLucas commented on May 12, 2024

Of course! In Core Data I save only the name of the file and then I rebuild the url when I want to play the file. Therefore, if I use the URL directly stored in CD, I receive the following error.UserInfo={NSUnderlyingError=0x600001d1c3c0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}, I assume is because it doesn't have the full url, only the name of the file.

So I have created a method to get the full URL and then use that variable in WaveformView(audioURL: . This is the method:

func getFile(fileName: String) -> URL { fileURL = FileManager.documentsDirectory.appendingPathComponent(fileName) return fileURL! }

(I've to force-unwrap fileURL using '!' because that variable is optional because I don't give it any default value in @State var fileURL?.)

But then, when I use the variable fileURL inside WaveformView() the app crash with error Fatal error: Unexpectedly found nil while unwrapping an Optional
Could it be that the origin of error is make optional the variable @State var fileURL? But I'm not sure.

The audio files plays correctly.

If you need more information, don't hesitate to ask me. Thank you very much for your help!

from dswaveformimage.

dmrschmidt avatar dmrschmidt commented on May 12, 2024

Got it. Thanks. And are you playing the file using the exact same URL from the same variable? Or is there any chance the player and the WaveformView are receiving slightly different URLs?

This here seems to be the interesting part: Which line is that originating from?

Fatal error: Unexpectedly found nil while unwrapping an Optional

from dswaveformimage.

CacereLucas avatar CacereLucas commented on May 12, 2024

I think I know where the possible mistake is. For some reason, the method I have created to complete the URL is not working. Look at this image:

Captura de pantalla 2022-09-24 a las 14 32 30

I really don't know why is unused frankly.

Which line is that originating from?

In the line where I have the WaveformView:

Captura de pantalla 2022-09-24 a las 14 32 36

Now is more clear why founds nil if the getFile method is not working, I suppose. Any idea how to solved this?

from dswaveformimage.

dmrschmidt avatar dmrschmidt commented on May 12, 2024

Sorry for the delay.

OK I see. There's two separate issues here in the code you shared:

That yellow warning actually gives the first hint. Result of call is unused. You're not actually assigning the URL to anything. And from your previous post I'm seeing that it's signature is func getFile(fileName: String) -> URL, so it is returning the URL and you'd need to assign that to something to keep it. What I can't see of course is whether it has any side effects internally.

So what you probably want is sth like

@State var fileURL: URL?
// ...
.onAppear {
    fileURL = func getFile(fileName: recording.url!)
    // ...
}
// ...
VStack {
    WaveformView(audioURL: $fileURL!, configuration: $configuration)
}

So the 2nd issue is, that you're wrapping the $fileURL in that Binding($fileUrl)! which is the part that throws the error. That's not how bindings work. You need an @State or @Published variable somewhere to actually hold that value.

Hope that helps.

from dswaveformimage.

CacereLucas avatar CacereLucas commented on May 12, 2024

We're making progress here :)

Thanks to your example code the first issue is resolved. I don't have any more the yellow warning.

For the second issue, I used Binding($fileUrl)!because I have an @State variable, exactly the same as your example: @State var fileURL: URL? but it's optional and I can't really write WaveformView(audioURL: $fileURL!) because it throws me an error.: audioURL expect 'Binding insteadBinding<URL?>. So, my solution was use Binding($fileUrl)!`, but is not working :(

I really appreciate your time helping me.

from dswaveformimage.

dmrschmidt avatar dmrschmidt commented on May 12, 2024

Ah right, I see. I didn't try to run the code, so my bad for not catching this. So you'll need to convert your optional Binding to a non-optional one (just an example link).

Looking at this holistically, it would arguably make life easier if WaveformView wouldn't expect a Binding but rather a plain URL, so one could simply guard against nil. As that's not currently how the API looks, I'm afraid you're left with 2 options that I can see. The above optional to non-optional road - depending on your code there may be an elegant solution higher up the hierarchy - or, just re-implementing WaveformView, simply removing the @Binding.

from dswaveformimage.

CacereLucas avatar CacereLucas commented on May 12, 2024

Hi @dmrschmidt

Sorry for the delay.

I have chosen the second option re-implementing WaveformView and now it works! So thank you for all your help!

from dswaveformimage.

CacereLucas avatar CacereLucas commented on May 12, 2024

Awesome!

I have implemented version 11.0.0 of the API in a side-project that has basically the same implementation as the previous one and has worked like charm!!! So for me this update is a great improvement in the API :)

from dswaveformimage.

dmrschmidt avatar dmrschmidt commented on May 12, 2024

Great to hear :) Hope all goes smooth from here on.

from dswaveformimage.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.