Skip to content

Instantly share code, notes, and snippets.

@mkchoi212
Last active July 16, 2018 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkchoi212/b951767108d5be4834ecf26289d8a9b5 to your computer and use it in GitHub Desktop.
Save mkchoi212/b951767108d5be4834ecf26289d8a9b5 to your computer and use it in GitHub Desktop.
UI API called on a background thread problem while testing VLCMediaPlayer
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
})
}
}
@mkchoi212
Copy link
Author

On macosx.m:381

NSRect bounds = [sys->glView convertRectToBacking:[sys->glView bounds]]; 

Xcode raises a SIGABRT signal with the following message

Main Thread Checker: UI API called on a background thread: -[NSView bounds]
-[NSView bounds] must be used from main thread only

@mkchoi212
Copy link
Author

mkchoi212 commented Jul 16, 2018

I got it to work by following this "trick" where we just turn off the Main Thread Checker. Not sure if it's the ideal solution here though :p

Maybe we should just create a separate UI test for these kind of functions?

@fkuehne
Copy link

fkuehne commented Jul 16, 2018

This issue is resolved in VLC master and VLC 3.0. Please update your libvlc check-out :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment