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

Jc/develop/play next music track #114

Open
wants to merge 4 commits into
base: tt/fix/podcast-fixes
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
4 changes: 2 additions & 2 deletions sphinx.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5458,7 +5458,7 @@
"\"UIKit\"",
"-ObjC",
);
PRODUCT_BUNDLE_IDENTIFIER = com.gl.sphinx;
PRODUCT_BUNDLE_IDENTIFIER = "com.gl.sphinx";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "$(PROJECT_DIR)/sphinx/Crypter/Sphinxrs-Bridging-Header.h";
SWIFT_VERSION = 4.2;
Expand Down Expand Up @@ -5551,7 +5551,7 @@
"\"UIKit\"",
"-ObjC",
);
PRODUCT_BUNDLE_IDENTIFIER = com.gl.sphinx;
PRODUCT_BUNDLE_IDENTIFIER = "com.gl.sphinx";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "$(PROJECT_DIR)/sphinx/Crypter/Sphinxrs-Bridging-Header.h";
SWIFT_VERSION = 4.2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ extension PodcastEpisode {
return podcastEpisode
}

func isMostLikelyMusic()->Bool{
if let valid_feed = self.feed,
let valid_pd = valid_feed.podcastDescription,
valid_pd.contains("music"){
return true
}
else if(self.duration ?? 0 < (60 * 10)){
return true
}
return false
}

var isMusicClip: Bool {
return type == RecommendationsHelper.PODCAST_TYPE || type == RecommendationsHelper.TWITTER_TYPE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ class PodcastPlayerHelper {
guard let player = player, let item = player.currentItem else {
return
}

print(player.currentTime().value)
print(player.currentTime().timescale)
let duration = Int(Double(item.asset.duration.value) / Double(item.asset.duration.timescale))
let currentTime = Int(round(Double(player.currentTime().value) / Double(player.currentTime().timescale)))

Expand Down Expand Up @@ -559,6 +560,8 @@ class PodcastPlayerHelper {
) {
var newTime = podcast.currentTime + Int(seconds)
newTime = newTime > 0 ? newTime : 0
let duration = podcast.getCurrentEpisode()?.duration ?? 0
newTime = newTime > duration ? duration : newTime

if podcast.feedID != self.podcast?.feedID {
podcast.currentTime = newTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ extension NewPodcastPlayerViewController : PodcastEpisodesDSDelegate {
}

extension NewPodcastPlayerViewController : PodcastPlayerViewDelegate {
func getCurrentEpisodeIndex() -> Int? {
return self.tableDataSource.podcast.getCurrentEpisodeIndex()
}

func getTotalEpisodeCount() -> Int? {
return tableView.numberOfRows(inSection: 0)
}

func didTapSubscriptionToggleButton() {
if let objectID = podcast.objectID {
Expand Down
36 changes: 33 additions & 3 deletions sphinx/Scenes/WebAppsAndPodcasts/Views/PodcastPlayerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ protocol PodcastPlayerViewDelegate: AnyObject {
func shouldShareClip(comment: PodcastComment)
func shouldSyncPodcast()
func shouldShowSpeedPicker()
func getCurrentEpisodeIndex()->Int?
func getTotalEpisodeCount()->Int?
}

class PodcastPlayerView: UIView {
Expand Down Expand Up @@ -60,8 +62,9 @@ class PodcastPlayerView: UIView {

let feedBoostHelper = FeedBoostHelper()
var playerHelper: PodcastPlayerHelper = PodcastPlayerHelper.sharedInstance

var startingIndex : Int = 0
var podcast: PodcastFeed! = nil
var isHittingNextTrack = false

var chat: Chat? {
get {
Expand All @@ -81,7 +84,8 @@ class PodcastPlayerView: UIView {
podcast: PodcastFeed,
delegate: PodcastPlayerViewDelegate,
boostDelegate: CustomBoostDelegate,
fromDashboard: Bool
fromDashboard: Bool,
startingIndex:Int = 0
) {
let windowWidth = WindowsManager.getWindowWidth()
let frame = CGRect(x: 0, y: 0, width: windowWidth, height: windowWidth + PodcastPlayerView.kPlayerHeight)
Expand All @@ -103,6 +107,26 @@ class PodcastPlayerView: UIView {

setupView()
setupActions(fromDashboard)

DispatchQueue.main.asyncAfter(deadline: .now() + 2.0, execute: {
//self.playNextMusicTrack()
})
}

func playNextMusicTrack(){
if let valid_episode = podcast.getCurrentEpisode(),
(valid_episode.isMostLikelyMusic()),
let valid_delegate = delegate,
let valid_index = valid_delegate.getCurrentEpisodeIndex(),
let valid_total = valid_delegate.getTotalEpisodeCount(),
valid_total > valid_index{
DispatchQueue.main.async {
if(self.isHittingNextTrack == false){
self.isHittingNextTrack = true
self.didTapEpisodeAt(index: valid_index + 1)
}
}
}
}

private var subscriptionToggleButtonTitle: String {
Expand Down Expand Up @@ -167,7 +191,6 @@ class PodcastPlayerView: UIView {

func loadTime() {
let episode = podcast.getCurrentEpisode()

if let duration = episode?.duration {
let _ = setProgress(
duration: duration,
Expand Down Expand Up @@ -263,6 +286,13 @@ class PodcastPlayerView: UIView {
progressLineWidth.constant = progressWidth
progressLine.layoutIfNeeded()

if(progress >= 0.995){
playNextMusicTrack()
}
else if(progress >= 0.01){
self.isHittingNextTrack = false
}

return didChangeCurrentTime
}

Expand Down