Skip to content

Commit

Permalink
Merge pull request #81 from Athlon007/dev
Browse files Browse the repository at this point in the history
Bug fix for video player
  • Loading branch information
Athlon007 committed Jul 30, 2023
2 parents a2ef003 + 28d7d76 commit 4685b68
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.4.1 (2023-07-30)

### Bug Fixes

- Fixed app crashing when trying to process posts with videos that are NOT on YouTube

## 0.4 (2023-07-29)

### Added
Expand Down
4 changes: 2 additions & 2 deletions Leomard.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 0.4;
MARKETING_VERSION = 0.4.1;
PRODUCT_BUNDLE_IDENTIFIER = com.Athlon.Leomard;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -1332,7 +1332,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 0.4;
MARKETING_VERSION = 0.4.1;
PRODUCT_BUNDLE_IDENTIFIER = com.Athlon.Leomard;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -878,8 +878,8 @@
filePath = "Leomard/Views/Components/PostUIView.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "573"
endingLineNumber = "573"
startingLineNumber = "577"
endingLineNumber = "577"
landmarkName = "deletePost()"
landmarkType = "7">
</BreakpointContent>
Expand All @@ -894,8 +894,8 @@
filePath = "Leomard/Views/Components/PostUIView.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "575"
endingLineNumber = "575"
startingLineNumber = "579"
endingLineNumber = "579"
landmarkName = "deletePost()"
landmarkType = "7">
</BreakpointContent>
Expand Down Expand Up @@ -1924,5 +1924,37 @@
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "F040EE27-AA89-4268-AFDE-E14B8FFD4AF3"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Leomard/Views/Components/AnimatedImage.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "124"
endingLineNumber = "124"
landmarkName = "updateNSView(_:context:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "6DCB68C6-2AAD-469E-9176-385813027321"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Leomard/Views/Components/AnimatedImage.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "128"
endingLineNumber = "128"
landmarkName = "updateNSView(_:context:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
41 changes: 41 additions & 0 deletions Leomard/Views/Components/AnimatedImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,47 @@ struct YoutubePlayer: NSViewRepresentable {
}
}

struct WebVideoPlayer: NSViewRepresentable {
let link: String
@Binding var imageHeight: CGFloat


func makeNSView(context: Context) -> WKWebVideoNonInteractable {
return WKWebVideoNonInteractable()
}

func updateNSView(_ nsView: WKWebVideoNonInteractable, context: Context) {
let type = link.components(separatedBy: ".").last ?? "mp4"

let html = """
<html>
<head>
<style>
html, body {
margin: 0;
padding: 0;
overflow: hidden;
font-family: sans-serif;
}
video {
width: 100%;
height: 100%;
object-fit: contain;
}
</style>
</head>
<body>
<video controls>
<source src="\(link)" type="video/\(type)">
Sorry! Failed to load the video :(<br>Here's the link: \(link)
</video>
</body>
</html>
"""
nsView.loadHTMLString(html, baseURL: nil)
}
}


class WKWebViewNonInteractable: WKWebView
{
Expand Down
10 changes: 7 additions & 3 deletions Leomard/Views/Components/PostUIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ struct PostUIView: View {
gifOrImage
Spacer()
} else if postView.post.embedVideoUrl != nil && LinkHelper.isVideosLink(link: postView.post.embedVideoUrl!) {
VideoPlayer(player: AVPlayer(url: URL(string: postView.post.embedVideoUrl!)!))
.frame(maxWidth: .infinity, maxHeight: .infinity)
WebVideoPlayer(link: postView.post.embedVideoUrl!, imageHeight: $gifHeight)
.frame(minWidth: 0, maxWidth: .infinity, minHeight: gifHeight, maxHeight: .infinity, alignment: .leading)
}
}

Expand Down Expand Up @@ -336,7 +336,11 @@ struct PostUIView: View {

@ViewBuilder
private var gifOrImage: some View {
if LinkHelper.isAnimatedLink(link: postView.post.url!) {
if LinkHelper.isVideosLink(link: postView.post.url!) {
// Video
WebVideoPlayer(link: postView.post.url!, imageHeight: $gifHeight)
.frame(minWidth: 0, maxWidth: .infinity, minHeight: gifHeight, maxHeight: .infinity, alignment: .leading)
} else if LinkHelper.isAnimatedLink(link: postView.post.url!) {
// Image-only view.
// GIF
AnimatedImage(link: postView.post.url!, imageHeight: $gifHeight)
Expand Down

0 comments on commit 4685b68

Please sign in to comment.