From 06e6f84867a67c222ccd27d76cafebceb08639ba Mon Sep 17 00:00:00 2001 From: Mayhem Date: Wed, 9 Apr 2014 10:04:51 +0200 Subject: [PATCH] Handle webm playback errors with image expansion. --- CHANGELOG.md | 2 ++ src/Images/ImageExpand.coffee | 23 ++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21ece63cf..0f9a35998 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +- Better handling of webm playback errors. + ### 3.20.3 - *2014-04-07* - Dramatically decreased CPU usage by pausing webm files not in the viewport. diff --git a/src/Images/ImageExpand.coffee b/src/Images/ImageExpand.coffee index f21c830d2..d7d00c0cc 100644 --- a/src/Images/ImageExpand.coffee +++ b/src/Images/ImageExpand.coffee @@ -17,6 +17,8 @@ ImageExpand = return unless @file and (@file.isImage or @file.isVideo) $.on @file.thumb.parentNode, 'click', ImageExpand.cb.toggle if @isClone + if @file.error + @file.error = $ '.warning', @file.thumb.parentNode if @file.isImage and @file.isExpanding # If we clone a post where the image is still loading, # make it loading in the clone too. @@ -83,7 +85,7 @@ ImageExpand = $.rmClass post.nodes.root, 'expanded-image' $.rmClass post.file.thumb, 'expanding' delete post.file.isExpanding - post.file.isExpanded = false + delete post.file.isExpanded post.file.fullImage.pause() if post.file.isVideo and post.file.fullImage expand: (post, src) -> @@ -102,6 +104,9 @@ ImageExpand = file.src = src or post.file.URL $.on file, 'error', ImageExpand.error ImageExpand.waitExpand post + if post.file.error + $.rm post.file.error + delete post.file.error $.after post.file.thumb, file waitExpand: (post) -> @@ -151,17 +156,29 @@ ImageExpand = error: -> post = Get.postFromNode @ - post.file.isReady = false $.rm @ + delete post.file.isReady delete post.file.fullImage # Images can error: # - before the image started loading. # - after the image started loading. unless post.file.isExpanding or post.file.isExpanded - # Don't try to re-expend if it was already contracted. + # Don't try to re-expand if it was already contracted. return ImageExpand.contract post + if @error and @error.code isnt @error.MEDIA_ERR_NETWORK # video + error = switch @error.code + when 1 then 'MEDIA_ERR_ABORTED' + when 3 then 'MEDIA_ERR_DECODE' + when 4 then 'MEDIA_ERR_SRC_NOT_SUPPORTED' + when 5 then 'MEDIA_ERR_ENCRYPTED' + post.file.error = $.el 'div', + textContent: "Playback error: #{error}" + className: 'warning' + $.after post.file.thumb, post.file.error + return + src = @src.split '/' if src[2] is 'i.4cdn.org' URL = Redirect.to 'file',