Comments (11)
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.
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.
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.
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.
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:
I really don't know why is unused frankly.
Which line is that originating from?
In the line where I have the WaveformView:
Now is more clear why founds nil if the getFile
method is not working, I suppose. Any idea how to solved this?
from dswaveformimage.
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.
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 instead
Binding<URL?>. So, my solution was use
Binding($fileUrl)!`, but is not working :(
I really appreciate your time helping me.
from dswaveformimage.
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.
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.
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.
Great to hear :) Hope all goes smooth from here on.
from dswaveformimage.
Related Issues (20)
- Wavefrom form Data in SwiftUI HOT 7
- WaveformLiveView for Local Path HOT 13
- There's many different ways this could be achieved. HOT 3
- Fatal error HOT 3
- Current amplitude HOT 1
- Empty audio not displayed even with Should Draw Silence HOT 6
- Compile error in Xcode 15 beta. HOT 2
- Missing Pause Functionality HOT 1
- -11800 Error code when generation samples on iOS 17 beta HOT 10
- mp3 File not support HOT 8
- xcode 15 not support. Stored properties cannot be marked unavailable with '@available' HOT 1
- Striped style with gradient HOT 2
- Stored properties cannot be marked unavailable with '@available' HOT 3
- Stored properties cannot be marked unavailable with '@available' HOT 1
- Thread 1: EXC_BAD_ACCESS (code=2, address=0x2829857c4) HOT 1
- WaveForm Flickering HOT 2
- Extra argument position in call error in MacOS HOT 1
- I need to show loader till complete image generating from audio URL. HOT 2
- Update version in cocoapod HOT 2
- crash in iOS 17 HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dswaveformimage.