Last active
July 16, 2018 14:36
-
-
Save mkchoi212/b951767108d5be4834ecf26289d8a9b5 to your computer and use it in GitHub Desktop.
UI API called on a background thread problem while testing VLCMediaPlayer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MockMediaPlayerDelegate: NSObject, VLCMediaPlayerDelegate { | |
let stateExpectation: XCTestExpectation? | |
init(stateExpectation: XCTestExpectation) { | |
self.stateExpectation = stateExpectation | |
} | |
func mediaPlayerStateChanged(_ aNotification: Notification!) { | |
guard let mediaPlayer = aNotification.object as? VLCMediaPlayer else { | |
XCTFail("VLCMediaPlayer is not passed to mejdiaPlayerStateChanged") | |
return | |
} | |
if mediaPlayer.state == .playing { | |
stateExpectation?.fulfill() | |
} | |
} | |
} | |
class VLCMediaPlayerDelegateTest: XCTestCase { | |
func testMediaPlayerStateChanged() throws { | |
let view = VLCVideoView(frame: .zero) | |
let mediaPlayer = try XCTAssertNotNilAndUnwrap(VLCMediaPlayer(videoView: view)) | |
mediaPlayer.media = Video.test1.media | |
XCTAssertEqual(mediaPlayer.state, .stopped) | |
let states: [VLCMediaPlayerState] = [.opening, .buffering, .esAdded, .playing] | |
let expectations = states.map { keyValueObservingMediaState(for: mediaPlayer, state: $0) } | |
mediaPlayer.play() | |
wait(for: expectations, timeout: STANDARD_TIME_OUT) | |
} | |
} | |
extension XCTestCase { | |
func keyValueObservingMediaState(for mediaPlayer: VLCMediaPlayer, state: VLCMediaPlayerState) -> XCTestExpectation { | |
return keyValueObservingExpectation(for: mediaPlayer, keyPath: "state", handler: { (obj, _) -> Bool in | |
NSLog(String(state.rawValue)) | |
return (obj as? VLCMediaPlayer)?.state == state | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This issue is resolved in VLC master and VLC 3.0. Please update your libvlc check-out :)