# Embrace the power of SwiftUI and Combine with the Bitmovin Player SDK on iOS and tvOS

**URL:** <https://community.bitmovin.com/t/embrace-the-power-of-swiftui-and-combine-with-the-bitmovin-player-sdk-on-ios-and-tvos/2295>\
**Category:** Knowledge\
**Tags:** ios, tvos, swiftui, combine\
**Created:** [August 31, 2023, 12:14pm UTC](https://community.bitmovin.com/t/embrace-the-power-of-swiftui-and-combine-with-the-bitmovin-player-sdk-on-ios-and-tvos/2295 "2023-08-31T12:14:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![roland.kakonyi](https://sea1.discourse-cdn.com/flex015/user_avatar/community.bitmovin.com/roland.kakonyi/32/177_2.png) [@roland.kakonyi](https://community.bitmovin.com/u/roland.kakonyi)\
**Post date:** [August 31, 2023, 12:14pm UTC](https://community.bitmovin.com/t/embrace-the-power-of-swiftui-and-combine-with-the-bitmovin-player-sdk-on-ios-and-tvos/2295/1 "2023-08-31T12:14:45Z")

</div>

To long to read? Check out [our video](https://streams.bitmovin.com/cmiee7s2nq86hg0pd9g0/share) introduction to Swift UI!

## Introduction

Starting from version `3.40.0`, Bitmovin’s Player iOS/tvOS SDK officially supports integrating with SwiftUI and/or Combine projects as a **first class citizen**. 🎉  
SwiftUI and Combine are two powerful frameworks introduced by Apple that simplify and speed up the development process and make your code cleaner and more robust.

## Single line SwiftUI integration

We introduced [`VideoPlayerView`](https://cdn.bitmovin.com/player/ios/3/docs/Structs/VideoPlayerView.html) to enable single line integration of our SDK into your SwiftUI view hierarchy.  
It is the equivalent of [`PlayerView`](https://cdn.bitmovin.com/player/ios/3/docs/Classes/PlayerView.html), but for SwiftUI.  
Once you have added our SDK to your iOS or tvOS project using our [guide](https://developer.bitmovin.com/playback/docs/getting-started-ios#step-1-add-the-sdk-to-your-project), all you need to do is to [create a `Player` instance](https://developer.bitmovin.com/playback/docs/getting-started-ios#step-2-set-up-the-player) and add a single line to your SwiftUI view:

```swift
VideoPlayerView(player: player)

```

### Full code snippet

The SwiftUI support enables you to get started **within minutes**.

```swift
struct ContentView: View {
    private let player: Player = {
        // Create player configuration
        let playerConfig = PlayerConfig()
        // Set your player license key on the player configuration
        playerConfig.key = "<PLAYER_LICENSE_KEY>"
        // Create player based on player configuration
        return PlayerFactory.create(playerConfig: playerConfig)
    }()

    private let sourceConfig: SourceConfig = {
        // Define needed resources
        guard let streamUrl = URL(string: "https://cdn.bitmovin.com/content/art-of-motion/m3u8s/playlist.m3u8"),
              let posterUrl = URL(string: "https://cdn.bitmovin.com/content/art-of-motion/poster.jpg") else {
            fatalError("Invalid URL")
        }
        return SourceConfig(url: streamUrl, type: .hls)
    }()

    var body: some View {
        VideoPlayerView(player: player)
            .background(Color.black)
            .onAppear {
                player.load(sourceConfig: sourceConfig)
            }
    }
}

```

You can find a **fully working application example** in our open-source sample project [here](https://github.com/bitmovin/bitmovin-player-ios-samples/blob/main/BasicPlayback/BasicPlayback/ContentView.swift).

> Tip: Our [Getting Started guide](https://developer.bitmovin.com/playback/docs/getting-started-ios#create-a-playerview-using-swiftui-or-uikit) was already updated to highlight the single line SwiftUI integration, making it easier than ever to get your video content displayed within your application.

## Reactive event subscription API using Combine

To enhance the support for modern application development trends, now you can use Apple’s own reactive framework, Combine, for subscribing to events. Using Combine for subscribing to individual or multiple events is simplified and allows the usage of standard Combine operators out-of-the-box. You can cancel an event subscription by releasing the `Cancellable` instance.

This is as easy as adding a couple of lines to your SwiftUI view:

```swift
VideoPlayerView(player: player)
    .onReceive(player.events.on(TimeChangedEvent.self)) { event in
        // Notified for every time changed event
        print("Time changed: \(event.currentTime)s")
    }

```

Or anywhere in your codebase:

```swift
player.events
    .on(TimeChangedEvent.self)
    .sink { timeChangedEvent in
        // Notified for every time changed event
        print("Time changed: \(event.currentTime)s")
    }
    .store(in: &cancellables)

```

> Tip: In case your project uses UIKit, you can still leverage the `events` API using Combine to simplify your integration.

This new API allows composition of event listeners in a declarative way, which enables the implementation of complex workflows with a couple lines of code:

```swift
Publishers.Merge(
    player.events.on(SourceErrorEvent.self).map(\.message)
    player.events.on(PlayerErrorEvent.self).map(\.message)
)
.sink { [weak self] errorMessage in
    // Notified for every source or player error
    print("Error message: \(errorMessage)")
}
.store(in: &cancellables)

```

The `events` API is supported on both [`Player`](https://cdn.bitmovin.com/player/ios/3/docs/Protocols/BMPPlayer.html#/c:objc(pl)BMPPlayer(py)events) and [`Source`](https://cdn.bitmovin.com/player/ios/3/docs/Protocols/Source.html#/c:@M@BitmovinPlayerCore@objc(pl)BMPSource(py)events), as well as on [`PlayerView`](https://cdn.bitmovin.com/player/ios/3/docs/Classes/PlayerView.html#/c:@M@BitmovinPlayerCore@objc(cs)BMPPlayerView(py)events).

To see all supported ways for subscribing to events, check out our brand new documentation page dedicated to showing how to listen to events, available [here](https://developer.bitmovin.com/playback/docs/listening-to-events-ios#combine-api).

## Summary

We are excited about the integration of SwiftUI and Combine in the Bitmovin Player SDK and look forward to seeing the amazing applications you will create with these new features.  
In case you are migrating from AVPlayer to Bitmovin Player, check out our [migration guide](https://developer.bitmovin.com/playback/docs/migrating-from-avplayer-to-the-bitmovin-player).

We always appreciate your feedback, so please feel free to share your thoughts and experiences with us.

Next, you can:

- check out our [Getting Started Guide](https://developer.bitmovin.com/playback/docs/getting-started-ios)
- learn more about [subscribing to events](https://developer.bitmovin.com/playback/docs/listening-to-events-ios)
- browse our [API reference](https://cdn.bitmovin.com/player/ios/3/docs/index.html)
- download and run our [`BasicPlayback` sample application](https://github.com/bitmovin/bitmovin-player-ios-samples/blob/main/BasicPlayback/BasicPlayback/ContentView.swift)
- follow our [AVPlayer to Bitmovin Player migration guide](https://developer.bitmovin.com/playback/docs/migrating-from-avplayer-to-the-bitmovin-player)

---

<div class="post-metadata">

**Author:** ![stefano.russello](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@stefano.russello](https://community.bitmovin.com/u/stefano.russello)\
**Post date:** [May 15, 2024, 11:41am UTC](https://community.bitmovin.com/t/embrace-the-power-of-swiftui-and-combine-with-the-bitmovin-player-sdk-on-ios-and-tvos/2295/2 "2024-05-15T11:41:10Z")

</div>

Thanks for this example @roland.kakonyi .  
What about enabling the fullscreen button on the bitmovin player using SwiftUI?  
The fullscreenHandler seems working only on UIKit.

---

<div class="post-metadata">

**Author:** ![roland.kakonyi](https://sea1.discourse-cdn.com/flex015/user_avatar/community.bitmovin.com/roland.kakonyi/32/177_2.png) [@roland.kakonyi](https://community.bitmovin.com/u/roland.kakonyi)\
**Post date:** [May 15, 2024, 11:59am UTC](https://community.bitmovin.com/t/embrace-the-power-of-swiftui-and-combine-with-the-bitmovin-player-sdk-on-ios-and-tvos/2295/3 "2024-05-15T11:59:27Z")

</div>

Hi @stefano.russello!

You are right, currently we don’t support full screen handler with SwiftUI.  
We are planning to add this feature later on but currently this isn’t planned for the near future!

---

<div class="post-metadata">

**Author:** ![stefano.russello](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@stefano.russello](https://community.bitmovin.com/u/stefano.russello)\
**Post date:** [September 5, 2024, 9:48am UTC](https://community.bitmovin.com/t/embrace-the-power-of-swiftui-and-combine-with-the-bitmovin-player-sdk-on-ios-and-tvos/2295/4 "2024-09-05T09:48:53Z")

</div>

@roland.kakonyi any news regarding when fullscreen hadler will be implemented on SwiftUI Bitmobin Player SDK?

---

<div class="post-metadata">

**Author:** ![stefano.russello](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@stefano.russello](https://community.bitmovin.com/u/stefano.russello)\
**Post date:** [May 15, 2025, 8:56am UTC](https://community.bitmovin.com/t/embrace-the-power-of-swiftui-and-combine-with-the-bitmovin-player-sdk-on-ios-and-tvos/2295/5 "2025-05-15T08:56:29Z")

</div>

Hey @roland.kakonyi after 1 year, do you have any news about this? Please let us know. Thank you!

---

<div class="post-metadata">

**Author:** ![roland.kakonyi](https://sea1.discourse-cdn.com/flex015/user_avatar/community.bitmovin.com/roland.kakonyi/32/177_2.png) [@roland.kakonyi](https://community.bitmovin.com/u/roland.kakonyi)\
**Post date:** [May 15, 2025, 11:05am UTC](https://community.bitmovin.com/t/embrace-the-power-of-swiftui-and-combine-with-the-bitmovin-player-sdk-on-ios-and-tvos/2295/6 "2025-05-15T11:05:28Z")

</div>

Hi @stefano.russello!

We don’t have this feature yet, please file a feature request through [dashboard.bitmovin.com](http://dashboard.bitmovin.com) so we can track the interest.
