Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global Renderer #18

Closed
robinfriedli opened this issue May 13, 2023 · 5 comments
Closed

Global Renderer #18

robinfriedli opened this issue May 13, 2023 · 5 comments

Comments

@robinfriedli
Copy link

Hi,

I'm trying to add a fullscreen toggle for my player but the problem is that it currently seems to be impossible to re-render the view without resetting the VLCMediaPlayer.

This is because the VLCVideoPlayer always creates a new UIVLCVideoPlayerView view:

public struct VLCVideoPlayer: _PlatformRepresentable {

    private var configuration: VLCVideoPlayer.Configuration
    private var proxy: VLCVideoPlayer.Proxy?
    private var onTicksUpdated: (Int, VLCVideoPlayer.PlaybackInformation) -> Void
    private var onStateUpdated: (VLCVideoPlayer.State, VLCVideoPlayer.PlaybackInformation) -> Void
    private var loggingInfo: (VLCVideoPlayerLogger, LoggingLevel)?

    #if os(macOS)
    public func makeNSView(context: Context) -> UIVLCVideoPlayerView {
        makeVideoPlayerView()
    }

    public func updateNSView(_ nsView: UIVLCVideoPlayerView, context: Context) {}
    #else
    public func makeUIView(context: Context) -> UIVLCVideoPlayerView {
        makeVideoPlayerView()
    }

    public func updateUIView(_ uiView: UIVLCVideoPlayerView, context: Context) {}
    #endif

    private func makeVideoPlayerView() -> UIVLCVideoPlayerView {
        UIVLCVideoPlayerView(
            configuration: configuration,
            proxy: proxy,
            onTicksUpdated: onTicksUpdated,
            onStateUpdated: onStateUpdated,
            loggingInfo: loggingInfo
        )
    }
}

which in turn always creates a new VLCMediaPlayer:

    init(
        configuration: VLCVideoPlayer.Configuration,
        proxy: VLCVideoPlayer.Proxy?,
        onTicksUpdated: @escaping (Int, VLCVideoPlayer.PlaybackInformation) -> Void,
        onStateUpdated: @escaping (VLCVideoPlayer.State, VLCVideoPlayer.PlaybackInformation) -> Void,
        loggingInfo: (VLCVideoPlayerLogger, VLCVideoPlayer.LoggingLevel)?
    ) {
        self.configuration = configuration
        self.proxy = proxy
        self.onTicksUpdated = onTicksUpdated
        self.onStateUpdated = onStateUpdated
        self.loggingInfo = loggingInfo
        super.init(frame: .zero)

        proxy?.videoPlayerView = self

        #if os(macOS)
        layer?.backgroundColor = .clear
        #else
        backgroundColor = .clear
        #endif

        setupVideoContentView()
        setupVLCMediaPlayer(with: configuration)
    }

    func setupVLCMediaPlayer(with newConfiguration: VLCVideoPlayer.Configuration) {
        currentMediaPlayer?.stop()
        currentMediaPlayer = nil

        let media = VLCMedia(url: newConfiguration.url)
        media.addOptions(newConfiguration.options)

        let newMediaPlayer = VLCMediaPlayer()
        newMediaPlayer.media = media
        newMediaPlayer.drawable = videoContentView
        newMediaPlayer.delegate = self

        if let loggingInfo = loggingInfo {
            newMediaPlayer.libraryInstance.debugLogging = true
            newMediaPlayer.libraryInstance.debugLoggingLevel = loggingInfo.level.rawValue.asInt32
            newMediaPlayer.libraryInstance.debugLoggingTarget = self
        }

        for child in newConfiguration.playbackChildren {
            newMediaPlayer.addPlaybackSlave(child.url, type: child.type.asVLCSlaveType, enforce: child.enforce)
        }

        configuration = newConfiguration
        currentMediaPlayer = newMediaPlayer
        proxy?.mediaPlayer = newMediaPlayer
        hasSetCurrentConfigurationValues = false
        lastPlayerTicks = 0
        lastPlayerState = .opening

        if newConfiguration.autoPlay {
            newMediaPlayer.play()
        }
    }

Would it be possible to change this behaviour to work more like SwiftUI's video player, which creates a new VideoPlayer view that references an existing AVPlayer? This would make implementing such use cases a lot more convenient.

@LePips
Copy link
Owner

LePips commented May 16, 2023

My only use for my project has only been a single view and I see your need as well. I can possibly look at a VLCRenderer object that you can manually pass into VLCVideoPlayer instances which holds the underlying VLCMediaPlayer and the underlying drawing layer.

To be clear, I am not "implementing full screen" as I leave all view implementations to developers.

@LePips LePips changed the title Enable support for fullscreen toggle Global Renderer May 16, 2023
@zmartell
Copy link

I would also really enjoy this as well, as every time I run "playnewmedia" it seems to destroy the old VLC instance, and spawn a new one potentially unnecessarily. If I can simply just pass "new media" URL/options, it would be far beneficial.

@LePips
Copy link
Owner

LePips commented May 16, 2023

That specific aspect wouldn't change here and is working as expected.

@zmartell
Copy link

That specific aspect wouldn't change here and is working as expected.

Oh. Seems I understand it wrong. Sorry.

@LePips
Copy link
Owner

LePips commented Jan 29, 2024

In the past year, I have taken a crack at this (and forgot to report my progress) but wasn't able to get anything. The branch global-renderer is now published which shows where I last left off but isn't encompassing of all of the things that I tried, that's just where I left off.

Unless I learn something grand and new that would allow such functionality, I'm not going to try for this.

@LePips LePips closed this as not planned Won't fix, can't repro, duplicate, stale Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants