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

Added set volume to proxy - Fix playing issue for m3u8 #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added Example/.DS_Store
Binary file not shown.
Binary file added Sources/.DS_Store
Binary file not shown.
Binary file added Sources/VLCUI/.DS_Store
Binary file not shown.
16 changes: 2 additions & 14 deletions Sources/VLCUI/UIVLCVideoPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,10 @@ extension UIVLCVideoPlayerView: VLCMediaPlayerDelegate {
onTicksUpdated(currentTicks.asInt, playbackInformation)

// Set playing state
if lastPlayerState != .playing,
abs(currentTicks - lastPlayerTicks) >= 200
{
if lastPlayerState != .playing, abs(currentTicks - lastPlayerTicks) >= 0 {
onStateUpdated(.playing, playbackInformation)
lastPlayerState = .playing
lastPlayerTicks = currentTicks

if !hasSetCurrentConfigurationValues {
setConfigurationValues(with: player, from: configuration)
hasSetCurrentConfigurationValues = true
Expand All @@ -212,8 +209,7 @@ extension UIVLCVideoPlayerView: VLCMediaPlayerDelegate {
// Replay
if configuration.replay,
lastPlayerState == .playing,
abs(player.media!.length.intValue - currentTicks) <= 500
{
abs(player.media!.length.intValue - currentTicks) <= 500 {
configuration.autoPlay = true
configuration.startTime = .ticks(0)
setupVLCMediaPlayer(with: configuration)
Expand All @@ -223,33 +219,25 @@ extension UIVLCVideoPlayerView: VLCMediaPlayerDelegate {
public func mediaPlayerStateChanged(_ aNotification: Notification) {
let player = aNotification.object as! VLCMediaPlayer
guard player.state != .playing, player.state != lastPlayerState else { return }

let wrappedState = VLCVideoPlayer.State(rawValue: player.state.rawValue) ?? .error
let playbackInformation = constructPlaybackInformation(player: player, media: player.media!)

onStateUpdated(wrappedState, playbackInformation)
lastPlayerState = player.state
}

private func setConfigurationValues(with player: VLCMediaPlayer, from configuration: VLCVideoPlayer.Configuration) {

player.time = VLCTime(int: configuration.startTime.asTicks.asInt32)

let defaultPlayerSpeed = player.rate(from: configuration.rate)
player.fastForward(atRate: defaultPlayerSpeed)

if configuration.aspectFill {
videoContentView.scale(x: aspectFillScale, y: aspectFillScale)
} else {
videoContentView.apply(transform: .identity)
}

let defaultSubtitleTrackIndex = player.subtitleTrackIndex(from: configuration.subtitleIndex)
player.currentVideoSubTitleIndex = defaultSubtitleTrackIndex.asInt32

let defaultAudioTrackIndex = player.audioTrackIndex(from: configuration.audioIndex)
player.currentAudioTrackIndex = defaultAudioTrackIndex.asInt32

player.setSubtitleSize(configuration.subtitleSize)
player.setSubtitleFont(configuration.subtitleFont)
player.setSubtitleColor(configuration.subtitleColor)
Expand Down
10 changes: 8 additions & 2 deletions Sources/VLCUI/VLCVideoPlayer/Proxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public extension VLCVideoPlayer {

weak var mediaPlayer: VLCMediaPlayer?
weak var videoPlayerView: UIVLCVideoPlayerView?

public init() {
self.mediaPlayer = nil
self.videoPlayerView = nil
Expand Down Expand Up @@ -94,7 +94,13 @@ public extension VLCVideoPlayer {
let newRate = mediaPlayer.rate(from: rate)
mediaPlayer.fastForward(atRate: newRate)
}


/// Set the player volume
public func setVolume(_ volume: Int32) {
guard let mediaPlayer = mediaPlayer else { return }
mediaPlayer.audio?.volume = volume
}

/// Aspect fill depending on the video's content size and the view's bounds, based
/// on the given percentage of completion
///
Expand Down