-
Notifications
You must be signed in to change notification settings - Fork 153
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
Fix: #94,#97,#99 #95
Open
gzlboy
wants to merge
9
commits into
exyte:main
Choose a base branch
from
gzlboy:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix: #94,#97,#99 #95
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7514307
Fix: When the recording duration is too long (for example, 2 minutes)…
gzlboy e07f5c5
Only one audio should be played at the same time.
gzlboy 37bb190
format code
gzlboy d268146
add copy button to message action menu
gzlboy 60e531e
New feature: supports audio play progress dragging.
gzlboy 0c644b8
New feature: support localizable.
gzlboy 6a2070b
Fix the date localization problem, do not set the DateFormatter regio…
gzlboy 95e35dd
Fix audio format bugs and support more custom audio attributes.
gzlboy b9966cd
Fixed the issue where the sound still plays after closing chatview.
gzlboy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ struct RecordWaveformWithButtons: View { | |
@Environment(\.chatTheme) private var theme | ||
|
||
@StateObject var recordPlayer = RecordingPlayer() | ||
//160 is screen left-padding/right-padding and playButton's width. | ||
//To ensure that the view does not exceed the screen, need to subtract | ||
static let viewPadding:CGFloat = 160 | ||
|
||
var recording: Recording | ||
|
||
|
@@ -53,20 +56,29 @@ struct RecordWaveformWithButtons: View { | |
} | ||
|
||
struct RecordWaveformPlaying: View { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please preserve the selected code style, namely:
|
||
var samples: [CGFloat] // 0...1 | ||
var progress: CGFloat | ||
var color: Color | ||
var addExtraDots: Bool | ||
|
||
var maxLength: CGFloat { | ||
max((RecordWaveform.spacing + RecordWaveform.width) * CGFloat(samples.count) - RecordWaveform.spacing, 0) | ||
var maxLength: CGFloat = 0.0 | ||
|
||
private var adjustedSamples: [CGFloat] = [] | ||
|
||
init(samples: [CGFloat], progress: CGFloat, color: Color, addExtraDots: Bool) { | ||
self.samples = samples | ||
self.progress = progress | ||
self.color = color | ||
self.addExtraDots = addExtraDots | ||
self.adjustedSamples = adjustedSamples(UIScreen.main.bounds.width) | ||
self.maxLength = max((RecordWaveform.spacing + RecordWaveform.width) * CGFloat(self.adjustedSamples.count) - RecordWaveform.spacing, 0) | ||
} | ||
|
||
var body: some View { | ||
|
||
GeometryReader { g in | ||
ZStack { | ||
let adjusted = adjustedSamples(g.size.width) | ||
let adjusted = addExtraDots ? adjustedSamples(g.size.width) : adjustedSamples | ||
RecordWaveform(samples: adjusted, addExtraDots: addExtraDots) | ||
.foregroundColor(color.opacity(0.4)) | ||
RecordWaveform(samples: adjusted, addExtraDots: addExtraDots) | ||
|
@@ -77,6 +89,7 @@ struct RecordWaveformPlaying: View { | |
} | ||
} | ||
.frame(height: RecordWaveform.maxSampleHeight) | ||
|
||
} | ||
.frame(height: RecordWaveform.maxSampleHeight) | ||
.applyIf(!addExtraDots) { | ||
|
@@ -86,27 +99,22 @@ struct RecordWaveformPlaying: View { | |
.fixedSize(horizontal: !addExtraDots, vertical: true) | ||
} | ||
|
||
func adjustedSamples(_ width: CGFloat) -> [CGFloat] { | ||
let maxWidth = addExtraDots ? width : UIScreen.main.bounds.width | ||
let maxSamples = Int(maxWidth / (RecordWaveform.width + RecordWaveform.spacing)) | ||
|
||
var adjusted = samples | ||
var temp = [CGFloat]() | ||
while adjusted.count > maxSamples { | ||
var i = 0 | ||
while i < adjusted.count { | ||
if i == adjusted.count - 1 { | ||
temp.append(adjusted[i]) | ||
break | ||
} | ||
|
||
temp.append((adjusted[i] + adjusted[i+1])/2) | ||
i+=2 | ||
} | ||
adjusted = temp | ||
temp = [] | ||
func adjustedSamples(_ maxWidth: CGFloat) -> [CGFloat] { | ||
|
||
let maxSamples = Int((maxWidth - RecordWaveformWithButtons.viewPadding) / (RecordWaveform.width + RecordWaveform.spacing)) | ||
let temp = samples | ||
|
||
if temp.count <= maxSamples { | ||
return temp | ||
} | ||
//Use ceil to ensure that the adjusted.count will not be greater than maxSamples | ||
let ratio = Int(ceil( Double(temp.count) / Double(maxSamples) )) | ||
let adjusted = stride(from: 0, to: temp.count, by: ratio).map { | ||
temp[$0] | ||
} | ||
|
||
return adjusted | ||
|
||
} | ||
} | ||
|
||
|
@@ -126,9 +134,9 @@ struct RecordWaveform: View { | |
Capsule() | ||
.frame(width: RecordWaveform.width, height: RecordWaveform.maxSampleHeight * CGFloat(s)) | ||
} | ||
|
||
if addExtraDots { | ||
ForEach(samples.count..<Int(g.size.width / (RecordWaveform.width + RecordWaveform.spacing)), id: \.self) { _ in | ||
let maxSampleCounts = Int((g.size.width) / (RecordWaveform.width + RecordWaveform.spacing)) | ||
if addExtraDots && samples.count < maxSampleCounts { | ||
ForEach(samples.count..<maxSampleCounts, id: \.self) { _ in | ||
Capsule() | ||
.viewSize(RecordWaveform.width) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by admin on 2024/9/17. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Notification.Name { | ||
static let chatAudioIsPlaying = Notification.Name("chatAudioIsPlaying") | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how can you guarantee that this will always be 160? you should pass this value using frame getters from wherever it is set in