Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,20 @@ import OggDecoder
```swift
let decoder = OGGDecoder()
let oggFile = oggFileURL()

// Using completion handler
decoder.decode(oggFile) { (savedWavUrl: URL?) in
// Do whatever you want with URL
// If convert was fail, returned url is nil
}

// Using async
Task {
let outputUrl = await decoder.decode(oggFile)

var wavAudioUrl: URL!
let result = await decoder.decode(oggFile, into: wavAudioUrl)
}
```

Available methods:
Expand All @@ -46,7 +56,8 @@ decoder.decode(URL) -> URL?
decoder.decode(URL, completion: (URL?) -> Void)
decoder.decode(URL, into: URL) -> bool
decoder.decode(URL, into: URL, completion: (Bool) -> Void)

decoder.decode(URL) async -> URL?
decoder.decode(URL, into: URL) async -> Bool
```

## License
Expand Down
10 changes: 10 additions & 0 deletions Sources/OggDecoderObjC/include/OGGDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ NS_ASSUME_NONNULL_BEGIN
-(void)decode:(NSURL*)oggFile into:(NSURL*)outputFile completion:(void (^)(BOOL))completion;
-(nullable NSURL*)decode:(NSURL*)oggFile;
-(void)decode:(NSURL*)oggFile completion:(void (^)(NSURL* _Nullable outputFile))completion;

// async/await exposure for Swift
#if __has_attribute(availability)
-(void)decode:(NSURL *)oggFile completion:(void (^)(NSURL * _Nullable))completionHandler NS_SWIFT_ASYNC_NAME(decode(oggFile:)) API_AVAILABLE(ios(15.0), macos(12.0));
-(void)decode:(NSURL *)oggFile into:(NSURL *)outputFile completion:(void (^)(BOOL))completionHandler NS_SWIFT_ASYNC_NAME(decode(oggFile:into:)) API_AVAILABLE(ios(15.0), macos(12.0));
#else
-(void)decode:(NSURL *)oggFile completion:(void (^)(NSURL * _Nullable))completionHandler NS_SWIFT_ASYNC_NAME(decode(oggFile:));
-(void)decode:(NSURL *)oggFile into:(NSURL *)outputFile completion:(void (^)(BOOL))completionHandler NS_SWIFT_ASYNC_NAME(decode(oggFile:into:));
#endif

@end

NS_ASSUME_NONNULL_END
Expand Down
27 changes: 27 additions & 0 deletions Tests/OggDecoderTests/OggDecoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,33 @@ final class OggDecoderTests: XCTestCase {
waitForExpectations(timeout: 60)
}

@available(iOS 15.0, macOS 12.0, *)
func test_decodeOggAudio_asyncAwait_returnsTrue() async throws {
let oggAudioUrl = try fetchFileUrlFromTestBundle(filename: "TestResources/Chopin-polonaise-in-a-military", ext: "ogg")
let result = await decoder.decode(oggAudioUrl, into: wavAudioUrl)
XCTAssertTrue(result)
}

@available(iOS 15.0, macOS 12.0, *)
func test_decodeOgaAudio_asyncAwait_returnsTrue() async throws {
let ogaAudioUrl = try fetchFileUrlFromTestBundle(filename: "TestResources/Chopin_-_Polonaise_Op._53", ext: "oga")
let result = await decoder.decode(ogaAudioUrl, into: wavAudioUrl)
XCTAssertTrue(result)
}

@available(iOS 15.0, macOS 12.0, *)
func test_decodeOggAudio_asyncAwait_returnsFileUrl() async throws {
let oggAudioUrl = try fetchFileUrlFromTestBundle(filename: "TestResources/Chopin-polonaise-in-a-military", ext: "ogg")
let outputUrl = await decoder.decode(oggAudioUrl)
XCTAssertNotNil(outputUrl)
}

@available(iOS 15.0, macOS 12.0, *)
func test_decodeOgaAudio_asyncAwait_returnsFileUrl() async throws {
let ogaAudioUrl = try fetchFileUrlFromTestBundle(filename: "TestResources/Chopin_-_Polonaise_Op._53", ext: "oga")
let outputUrl = await decoder.decode(ogaAudioUrl)
XCTAssertNotNil(outputUrl)
}

private func fetchFileUrlFromTestBundle(filename: String, ext: String) throws -> URL {
let bundle = Bundle.module
Expand Down