posts: show length of videos and animations in thumbnails.
Show the length of videos and animated posts in the thumbnail. The length is shown the top left corner in MM:SS format. This replaces the play button icon. Show a speaker icon instead of a music note icon for posts with sound. Doing this requires doing `.includes(:media_asset)` in a bunch of places to avoid N+1 queries when we access the post's duration.
This commit is contained in:
@@ -102,6 +102,20 @@ module ApplicationHelper
|
||||
end
|
||||
end
|
||||
|
||||
def duration_to_hhmmss(seconds)
|
||||
hh = seconds.div(1.hour).to_s
|
||||
mm = seconds.div(1.minute).to_s
|
||||
ss = "%.2d" % (seconds.round % 1.minute)
|
||||
|
||||
if seconds >= 1.hour
|
||||
"#{hh}:#{mm}:#{ss}"
|
||||
elsif seconds >= 1.second
|
||||
"#{mm}:#{ss}"
|
||||
else
|
||||
"0:01"
|
||||
end
|
||||
end
|
||||
|
||||
def humanized_number(number)
|
||||
if number >= 1_000_000
|
||||
format("%.1fM", number / 1_000_000.0)
|
||||
|
||||
Reference in New Issue
Block a user