diff --git a/htroot/env/base.css b/htroot/env/base.css index 9134a5168..bce01887e 100644 --- a/htroot/env/base.css +++ b/htroot/env/base.css @@ -1128,6 +1128,16 @@ div#tagcloud { /******* yacysearchtrailer.html end ***********/ +/******* yacysearchitem.html **********/ + +/* Mark audio element with media playing error */ +.audioError { + border-style: solid; + border-color: orange; +} + +/******* yacysearchitem.html end ***********/ + /******* Vocabulary_p.html **********/ #Vocabulary_p label { diff --git a/htroot/js/yacysearch.js b/htroot/js/yacysearch.js index f9927f3bd..16b80ff15 100644 --- a/htroot/js/yacysearch.js +++ b/htroot/js/yacysearch.js @@ -284,5 +284,47 @@ function toggleMoreTags(button, moreTagsId) { moreTagsContainer.className = ""; } } - +} + +/** + * Handle embedded audio result load error. + * + * @param event + * {ErrorEvent} the error event triggered + */ +function handleAudioLoadError(event) { + if (event != null && event.target != null) { + /* Fill the title attribute to provide some feedback about the error without need for looking at the console */ + if (event.target.error != null && event.target.error.message) { + event.target.title = "Cannot play (" + + event.target.error.message + ")"; + } else { + event.target.title = "Cannot play"; + } + + /* Apply CSS class marking error for visual feedback*/ + event.target.className = "audioError"; + } +} + +/** + * Handle embedded audio result 'playing' event : pauses any other currently + * playing audio. + * + * @param event + * {Event} a 'playing' event + */ +function handleAudioPlaying(event) { + if (event != null && event.target != null) { + var audioElems = document.getElementsByTagName("audio"); + if(audioElems != null) { + for (var i = 0; i < audioElems.length; i++) { + var audioElem = audioElems[i]; + if (audioElem != event.target && audioElem.pause + && !audioElem.paused) { + audioElem.pause(); + } + } + } + } } \ No newline at end of file diff --git a/htroot/yacysearch.html b/htroot/yacysearch.html index f4c7214b9..687439f25 100644 --- a/htroot/yacysearch.html +++ b/htroot/yacysearch.html @@ -199,7 +199,8 @@ document.getElementById("Enter").innerHTML = "search again";
-#(resultTable)#::#(/resultTable)# +#(resultTable)#::
MediaURL
+::
MediaURL
#(embed)#::#(/embed)##(/resultTable)# #(jsResort)# #{results}# @@ -208,7 +209,7 @@ document.getElementById("Enter").innerHTML = "search again";
#(/jsResort)# -#(resultTable)#::
MediaURLPlayer
#(/resultTable)# +#(resultTable)#::::#(/resultTable)# #(num-results)# diff --git a/htroot/yacysearch.java b/htroot/yacysearch.java index 3c61bfe3a..0144dc17b 100644 --- a/htroot/yacysearch.java +++ b/htroot/yacysearch.java @@ -902,7 +902,8 @@ public class yacysearch { } prop.put("results", theQuery.itemsPerPage()); prop.put("jsResort_results", theQuery.itemsPerPage()); - prop.put("resultTable", (contentdom == ContentDomain.APP || contentdom == ContentDomain.AUDIO || contentdom == ContentDomain.VIDEO) ? 1 : 0); + prop.put("resultTable", (contentdom == ContentDomain.APP || contentdom == ContentDomain.VIDEO) ? 1 : (contentdom == ContentDomain.AUDIO ? 2 : 0) ); + prop.put("resultTable_embed", (contentdom == ContentDomain.AUDIO && extendedSearchRights)); prop.put("eventID", theQuery.id(false)); // for bottomline prop.put("jsResort_eventID", theQuery.id(false)); diff --git a/htroot/yacysearchitem.html b/htroot/yacysearchitem.html index 6b8941c64..e833915f4 100644 --- a/htroot/yacysearchitem.html +++ b/htroot/yacysearchitem.html @@ -61,7 +61,12 @@
#[name]#
#[sourcedom]#
#(/item)# :: - #(item)#::#[name]##[hrefshort]##(/item)# + #(item)#:: + + #[name]# + #[hrefshort]# + #(embed)#::#(/embed)# + #(/item)# :: #(item)#::#[name]##[hrefshort]##(/item)# :: diff --git a/htroot/yacysearchitem.java b/htroot/yacysearchitem.java index 9e6357752..07eb89ce1 100644 --- a/htroot/yacysearchitem.java +++ b/htroot/yacysearchitem.java @@ -104,6 +104,8 @@ public class yacysearchitem { final UserDB.Entry user = sb.userDB != null ? sb.userDB.getUser(header) : null; final boolean authenticated = adminAuthenticated || user != null; + + final boolean extendedSearchRights = adminAuthenticated || (user != null && user.hasRight(UserDB.AccessRight.EXTENDED_SEARCH_RIGHT)); final int item = post.getInt("item", -1); final RequestHeader.FileType fileType = header.fileType(); @@ -450,6 +452,20 @@ public class yacysearchitem { final String resultUrlstring = ms.url().toNormalform(true); final String target = sb.getConfig(resultUrlstring.matches(target_special_pattern) ? SwitchboardConstants.SEARCH_TARGET_SPECIAL : SwitchboardConstants.SEARCH_TARGET_DEFAULT, "_self"); prop.putHTML("content_item_href", resultUrlstring); + final String mediaType = ms.mime(); + if (extendedSearchRights && mediaType != null && mediaType.startsWith("audio/")) { + /* + * Display HTML5 embedded audio only : + * - when content-type is known to be audio (each browser has its own set of supported audio subtypes, + * so the browser will then handle itself eventual report about unsupported media format) + * - to authenticated users with extended search rights to prevent any media redistribution issue + */ + prop.put("content_item_embed", true); + prop.putHTML("content_item_embed_href", resultUrlstring); + prop.putHTML("content_item_embed_mediaType", mediaType); + } else { + prop.put("content_item_embed", false); + } prop.put("content_item_noreferrer", noreferrer ? 1 : 0); prop.putHTML("content_item_hrefshort", nxTools.shortenURLString(resultUrlstring, MAX_URL_LENGTH)); prop.putHTML("content_item_target", target);