1 package org.readium.r2_streamer.model.publication.SMIL;
3 import com.fasterxml.jackson.annotation.JsonProperty;
5 import java.io.Serializable;
6 import java.util.ArrayList;
10 * Created by gautam chibde on 23/5/17.
13 public class MediaOverlays implements Serializable {
15 private static final long serialVersionUID = 335418192699543070L;
17 @JsonProperty("media-overlay")
18 public List<MediaOverlayNode> mediaOverlayNodes;
20 public MediaOverlays() {
21 this.mediaOverlayNodes = new ArrayList<>();
25 public String toString() {
26 return "MediaOverlays{" +
27 ", mediaOverlayNodes=" + mediaOverlayNodes +
32 * Function return the path of the audio file for the
35 * @param href page href
36 * @return audio file path for given SMIL
38 public String getAudioPath(String href) {
40 if (href.contains("/")) {
41 int startIndex = href.lastIndexOf("/");
42 href = href.substring(startIndex + 1, href.length());
44 String path = findAudioPath(href, this.mediaOverlayNodes);
54 * Return the file path from the first node element
56 * @param href href of page
57 * @param nodes media overlay nodes
58 * @return audio file path
60 private String findAudioPath(String href,
61 List<MediaOverlayNode> nodes) {
62 // For each node of the current scope..
63 for (MediaOverlayNode node : nodes) {
64 if (node.audio != null) {
65 if (node.text.contains(href)) {
66 if (node.audio.contains("#")) {
67 return node.audio.split("#")[0];
71 if (node.role.contains("section")) {
72 return findAudioPath(href, node.children);
80 * Get the audio `Clip` associated to an audio Fragment id.
81 * The fragment id can be found in the HTML document in <p> & <span> tags,
82 * it refer to a element of one of the SMIL files, providing information
83 * This function returns the clip representing this element from SMIL.
84 * about the synchronized audio.
87 * @param forFragmentId The audio fragment id.
88 * @return The `Clip`, representation of the associated SMIL element.
90 public Clip clip(String forFragmentId) {
91 MediaOverlayNode node = findNode(forFragmentId, this.mediaOverlayNodes);
101 * Find the node (<par>) corresponding to "fragment" ?? nil.
104 * @param fragment The current fragment name for which we are looking the
105 * @param nodes The set of MediaOverlayNodes where to search. Default to self children.
106 * @return node corresponding to the fragment id, null if not found
108 private MediaOverlayNode findNode(String fragment,
109 List<MediaOverlayNode> nodes) {
110 // For each node of the current scope..
111 for (MediaOverlayNode node : nodes) {
112 if (node.text.contains(fragment)) {
115 if (node.role.contains("section")) {
116 return findNode(fragment, node.children);