Commit 881516aa93856ef39d16d404a4b16f72610aefdc

Authored by Imanol-Mikel Barba Sabariego
1 parent eafc5031

--no commit message

.settings/org.eclipse.jdt.core.prefs
1 -eclipse.preferences.version=1  
2 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5  
3 -org.eclipse.jdt.core.compiler.compliance=1.5  
4 -org.eclipse.jdt.core.compiler.source=1.5 1 +eclipse.preferences.version=1
  2 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
  3 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
  4 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
  5 +org.eclipse.jdt.core.compiler.compliance=1.5
  6 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate
  7 +org.eclipse.jdt.core.compiler.debug.localVariable=generate
  8 +org.eclipse.jdt.core.compiler.debug.sourceFile=generate
  9 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
  10 +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
  11 +org.eclipse.jdt.core.compiler.source=1.5
src/com/upc/pbe/upcnews/ErrorException.java 0 → 100644
  1 +package com.upc.pbe.upcnews;
  2 +
  3 +public class ErrorException extends Exception
  4 +{
  5 + private static final long serialVersionUID = 1L;
  6 + public ErrorException(String message)
  7 + {
  8 + super(message);
  9 + }
  10 +}
src/com/upc/pbe/upcnews/MainActivity.java
@@ -18,7 +18,7 @@ public class MainActivity extends Activity implements OnClickListener { @@ -18,7 +18,7 @@ public class MainActivity extends Activity implements OnClickListener {
18 18
19 Button buttonDescarrega; 19 Button buttonDescarrega;
20 String file = "ejemplo.xml"; 20 String file = "ejemplo.xml";
21 - String folder = "Environment.getExternalStorageDirectory.getPath()"; // hauria de ser /sdcard/downloads 21 + String folder = "Environment.getExternalStorageDirectory.getPath()";
22 TextView showText, showRoute; 22 TextView showText, showRoute;
23 23
24 @Override 24 @Override
src/com/upc/pbe/upcnews/Parser.java
@@ -11,9 +11,9 @@ public class Parser @@ -11,9 +11,9 @@ public class Parser
11 11
12 } 12 }
13 13
14 - public void setPlaylist(Playlist m3u8) 14 + public void setPlaylist(Playlist pls)
15 { 15 {
16 - playlist = m3u8; 16 + playlist = pls;
17 } 17 }
18 18
19 public Playlist getPlaylist() 19 public Playlist getPlaylist()
@@ -21,54 +21,92 @@ public class Parser @@ -21,54 +21,92 @@ public class Parser
21 return playlist; 21 return playlist;
22 } 22 }
23 23
24 - public void parseLine(String line) 24 + public void parseLine(String line) throws ErrorException, WarningException
25 { 25 {
  26 + Playlist pls = getPlaylist();
26 int currentLine = 0; 27 int currentLine = 0;
27 - boolean m3u8Validated = false;  
28 - if(true) //NIGGRADA PER QUE TIRI, JA HO MIRARÉ 28 + int currentSegment = 0;
  29 + boolean expectSegment = false;
  30 +
  31 + if(pls == null)
  32 + {
  33 + throw new ErrorException("Playlist uninitialized");
  34 + }
  35 +
  36 + if(line.isEmpty())
29 { 37 {
30 currentLine++; 38 currentLine++;
31 return; 39 return;
32 } 40 }
33 else 41 else
34 { 42 {
35 - if(!m3u8Validated) 43 + if(!pls.getValidated())
36 { 44 {
37 if(line.equals(STARTWORD)) 45 if(line.equals(STARTWORD))
38 { 46 {
39 - m3u8Validated = true; 47 + pls.setValidated(true);
  48 + }
  49 + else
  50 + {
  51 + throw new ErrorException("Playlist is not valid");
40 } 52 }
41 } 53 }
  54 + else
  55 + {
  56 + if(line.charAt(0) == '#')
  57 + {
  58 + if(line.substring(0,4).equals("#EXT"))
  59 + {
  60 + String[] extTag = line.split(":");
  61 + //switch(extTag[0]) Esto no se puede usar hasta JDK7 y Android no lo permite, diffikultyz???
  62 + if(extTag[0].equals("#EXT-X-MEDIA-SEQUENCE"))
  63 + {
  64 + pls.setSequence(Integer.parseInt(extTag[1]));
  65 + }
  66 + else if(extTag[0].equals("#EXT-X-TARGETDURATION"))
  67 + {
  68 + pls.setMaxDuration(Integer.parseInt(extTag[1]));
  69 + }
  70 +
  71 + else if(extTag[0].equals("#EXTINF"))
  72 + {
  73 + String[] args = extTag[1].split(",");
  74 + int duration = Integer.parseInt(args[0]);
  75 + if (duration > pls.getMaxDuration())
  76 + {
  77 + throw new ErrorException("Segment " + currentSegment + " on line " + currentLine
  78 + +" exceeds max duration");
  79 + }
  80 + Segment s = new Segment(duration);
  81 + s.setName(args[1]);
  82 + pls.getSegments().add(s);
  83 + currentSegment++;
  84 + expectSegment = true;
  85 + }
  86 +
  87 + else if(extTag[0].equals("#EXT-X-STREAM-INF"))
  88 + {
  89 +
  90 + }
  91 +
  92 + else if(extTag[0].equals("#EXT-X-ENDLIST"))
  93 + {
  94 + //END REACHED, IGNORE AND LET THE FILE REACH EOF
  95 + }
  96 +
  97 + else
  98 + {
  99 + throw new WarningException("Tag not implemented");
  100 + }
  101 + }
  102 +
  103 + }
  104 +
  105 + }
42 } 106 }
43 107
44 108
45 - /*else  
46 - if [[ $M3U8_VALIDATED -eq 0 ]]; then  
47 - if [[ $line == "#EXTM3U" ]]; then  
48 - M3U8_VALIDATED=1  
49 - else  
50 - echo "ERROR: This is not an m3u8 file!!"  
51 - exit 1  
52 - fi  
53 - else  
54 - if [[ `echo $line | head -c1` == "#" ]]; then  
55 - if [[ `echo $line | head -c4` == "#EXT" ]]; then  
56 - case `echo $line | cut -d':' -f 1` in  
57 - "#EXT-X-MEDIA-SEQUENCE")  
58 - SEQUENCE_FIRST=`echo $line | cut -d':' -f 2`;  
59 - echo "INFO: First element to be played is: $SEQUENCE_FIRST";;  
60 - "#EXT-X-TARGETDURATION")  
61 - MAX_DURATION=`echo $line | cut -d':' -f 2`;  
62 - echo "INFO: Maximum segment duration is: $MAX_DURATION";;  
63 - "#EXTINF")  
64 - DURATION=`echo $line | cut -d':' -f 2 | cut -d',' -f 1`  
65 - if [[ $DURATION > $MAX_DURATION ]]; then  
66 - echo "ERROR: Segment $CURRENT_SEGMENT on line $CURRENT_LINE is larger than EXT-X-TARGETDURATION"  
67 - exit 1  
68 - else  
69 - NAME=`echo $line | cut -d':' -f 2 | cut -d',' -f 2`  
70 - EXTINF=1  
71 - fi;; 109 + /*
72 "#EXT-X-STREAM-INF") 110 "#EXT-X-STREAM-INF")
73 EXTXSTREAM=1 111 EXTXSTREAM=1
74 PROGRAMID="" 112 PROGRAMID=""
src/com/upc/pbe/upcnews/Playlist.java
1 package com.upc.pbe.upcnews; 1 package com.upc.pbe.upcnews;
2 2
  3 +import java.util.ArrayList;
  4 +
3 public class Playlist 5 public class Playlist
4 { 6 {
5 - 7 + private boolean validated;
  8 + private int sequenceFirst;
  9 + private int maxDuration;
  10 + private ArrayList<Segment> segments;
  11 +
  12 + public Playlist()
  13 + {
  14 + validated = false;
  15 + segments = new ArrayList<Segment>();
  16 + }
  17 +
  18 + public void setValidated(boolean val)
  19 + {
  20 + validated = val;
  21 + }
  22 +
  23 + public boolean getValidated()
  24 + {
  25 + return validated;
  26 + }
  27 +
  28 + public void setSequence(int seq)
  29 + {
  30 + sequenceFirst = seq;
  31 + }
  32 +
  33 + public int getSequence()
  34 + {
  35 + return sequenceFirst;
  36 + }
  37 +
  38 + public void setMaxDuration(int dur)
  39 + {
  40 + maxDuration = dur;
  41 + }
  42 +
  43 + public int getMaxDuration()
  44 + {
  45 + return maxDuration;
  46 + }
  47 +
  48 + public ArrayList<Segment> getSegments()
  49 + {
  50 + return segments;
  51 + }
6 } 52 }
  53 +
src/com/upc/pbe/upcnews/Segment.java 0 → 100644
  1 +package com.upc.pbe.upcnews;
  2 +
  3 +import java.net.MalformedURLException;
  4 +import java.net.URL;
  5 +
  6 +public class Segment
  7 +{
  8 + private String name;
  9 + private int duration;
  10 + private URL url;
  11 +
  12 + public Segment(int dur)
  13 + {
  14 + name = "";
  15 + duration = dur;
  16 + }
  17 +
  18 + public void setName(String nam)
  19 + {
  20 + name = nam;
  21 + }
  22 +
  23 + public String getName()
  24 + {
  25 + return name;
  26 + }
  27 +
  28 + public int getDuration()
  29 + {
  30 + return duration;
  31 + }
  32 + public void setURL(String url) throws MalformedURLException
  33 + {
  34 + this.url = new URL(url);
  35 + }
  36 +
  37 + public URL getURL()
  38 + {
  39 + return url;
  40 + }
  41 +}
src/com/upc/pbe/upcnews/WarningException.java 0 → 100644
  1 +package com.upc.pbe.upcnews;
  2 +
  3 +public class WarningException extends Exception
  4 +{
  5 + private static final long serialVersionUID = 1L;
  6 + public WarningException(String message)
  7 + {
  8 + super(message);
  9 + }
  10 +}