From f4285f8e3fcaa951b14b9f6b36a0c4be9412abad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matu=CC=81s=CC=8C=20Tomlein?= Date: Mon, 19 Aug 2024 10:46:36 +0200 Subject: [PATCH] Fix media tracking calls not being dispatched on the correct queue when tracking using AVPlayer --- Integrationtests/TestTrackEventsToMicro.swift | 13 +++++++++++++ .../InternalQueue/MediaControllerIQWrapper.swift | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Integrationtests/TestTrackEventsToMicro.swift b/Integrationtests/TestTrackEventsToMicro.swift index c57caffc2..d21984f02 100644 --- a/Integrationtests/TestTrackEventsToMicro.swift +++ b/Integrationtests/TestTrackEventsToMicro.swift @@ -13,6 +13,9 @@ import XCTest import SnowplowTracker +#if !os(watchOS) +import AVKit +#endif class TestTrackEventsToMicro: XCTestCase { var tracker: TrackerController? @@ -166,6 +169,16 @@ class TestTrackEventsToMicro: XCTestCase { ], timeout: Micro.timeout) } +#if !os(watchOS) + func testMediaTrackingUsingAVPlayer() { + let player = AVPlayer() + let mediaTracking = tracker?.media.startMediaTracking(player: player, configuration: MediaTrackingConfiguration(id: "integration-test")) + mediaTracking?.track(MediaReadyEvent()) + + wait(for: [Micro.expectCounts(good: 1)], timeout: Micro.timeout) + } +#endif + private func track(_ event: Event) { _ = tracker!.track(event) tracker!.emitter!.flush() diff --git a/Sources/Core/InternalQueue/MediaControllerIQWrapper.swift b/Sources/Core/InternalQueue/MediaControllerIQWrapper.swift index beaf0b2dc..e0b9dcc8d 100644 --- a/Sources/Core/InternalQueue/MediaControllerIQWrapper.swift +++ b/Sources/Core/InternalQueue/MediaControllerIQWrapper.swift @@ -45,7 +45,9 @@ class MediaControllerIQWrapper: MediaController { #if !os(watchOS) func startMediaTracking(player: AVPlayer, configuration: MediaTrackingConfiguration) -> MediaTracking { - return InternalQueue.sync { controller.startMediaTracking(player: player, configuration: configuration) } + return InternalQueue.sync { + MediaTrackingIQWrapper(tracking: controller.startMediaTracking(player: player, configuration: configuration)) + } } #endif