Commit 05eb43665f3efe9255dc5391e2b8b2d116903473

Authored by Imanol-Mikel Barba Sabariego
1 parent 0a050c2c

--no commit message

src/com/upc/pbe/upcnews/SegmentList.java renamed to src/com/upc/pbe/upcnews/List.java
... ... @@ -2,14 +2,15 @@ package com.upc.pbe.upcnews;
2 2  
3 3 import java.util.ArrayList;
4 4  
5   -public class SegmentList
  5 +public class List
6 6 {
7 7 private boolean validated;
8 8 private int sequenceFirst;
9 9 private int maxDuration;
10 10 private ArrayList<Segment> segments;
  11 + private ParentList parent;
11 12  
12   - public SegmentList()
  13 + public List()
13 14 {
14 15 validated = false;
15 16 segments = new ArrayList<Segment>();
... ... @@ -45,6 +46,16 @@ public class SegmentList
45 46 return maxDuration;
46 47 }
47 48  
  49 + public void setParent(ParentList p)
  50 + {
  51 + parent = p;
  52 + }
  53 +
  54 + public ParentList getParent()
  55 + {
  56 + return parent;
  57 + }
  58 +
48 59 public ArrayList<Segment> getSegments()
49 60 {
50 61 return segments;
... ...
src/com/upc/pbe/upcnews/ParentList.java 0 → 100644
  1 +package com.upc.pbe.upcnews;
  2 +
  3 +import java.util.ArrayList;
  4 +
  5 +public class ParentList
  6 +{
  7 + int currentID;
  8 + ArrayList<List> lists; //per cada qualitat
  9 +
  10 + public ParentList()
  11 + {
  12 + currentID = 0;
  13 + lists = new ArrayList<List>();
  14 + }
  15 +
  16 + public int getCurrent()
  17 + {
  18 + return currentID;
  19 + }
  20 +
  21 + public ArrayList<List> getLists()
  22 + {
  23 + return lists;
  24 + }
  25 +
  26 +
  27 +}
... ...
src/com/upc/pbe/upcnews/Parser.java
1 1 package com.upc.pbe.upcnews;
2 2  
  3 +import java.util.ArrayList;
  4 +
3 5 public class Parser
4   -{
5   - private SegmentList playlist;
6   -
  6 +{
7 7 private static final String STARTWORD = "#EXTM3U";
8 8  
9   - public Parser()
10   - {
11   -
12   - }
  9 + private int currentLine;
  10 + private int currentSegment;
  11 + private int currentList;
13 12  
14   - public void setPlaylist(SegmentList pls)
  13 + public Parser()
15 14 {
16   - playlist = pls;
  15 + currentLine = 0;
  16 + currentSegment = 0;
  17 + currentList = 0;
17 18 }
18 19  
19   - public SegmentList getPlaylist()
  20 + public ArrayList<ParentList> parseFile(String file) throws ErrorException, WarningException, InfoException
20 21 {
21   - return playlist;
  22 + ArrayList<ParentList> lists = new ArrayList<ParentList>();
  23 + lists.add(new ParentList());
  24 + lists.get(0).getLists().add(new List());
  25 + String[] lines = file.split("\n");
  26 + for(int i = 0; i < lines.length; i++)
  27 + {
  28 + parseLine(lines[i],lists);
  29 + }
  30 + return lists;
22 31 }
23 32  
24   - public void parseLine(String line) throws ErrorException, WarningException, InfoException
  33 + public void parseLine(String line, ArrayList<ParentList> lists) throws ErrorException, WarningException, InfoException
25 34 {
26   - SegmentList pls = getPlaylist();
27   - int currentLine = 0;
28   - int currentSegment = 0;
29 35 boolean expectSegment = false;
30 36 boolean expectList = false;
31 37  
32   - if(pls == null)
33   - {
34   - throw new ErrorException("Playlist uninitialized");
35   - }
36   -
37 38 if(line.isEmpty())
38 39 {
39 40 currentLine++;
... ... @@ -41,6 +42,7 @@ public class Parser
41 42 }
42 43 else
43 44 {
  45 + List pls = lists.get(currentList).getLists().get(lists.get(currentList).currentID);
44 46 if(!pls.getValidated())
45 47 {
46 48 if(line.equals(STARTWORD))
... ... @@ -59,7 +61,6 @@ public class Parser
59 61 if(line.substring(0,4).equals("#EXT"))
60 62 {
61 63 String[] extTag = line.split(":");
62   - //switch(extTag[0]) Esto no se puede usar hasta JDK7 y Android no lo permite, diffikultyz???
63 64 if(extTag[0].equals("#EXT-X-MEDIA-SEQUENCE"))
64 65 {
65 66 pls.setSequence(Integer.parseInt(extTag[1]));
... ... @@ -87,8 +88,8 @@ public class Parser
87 88  
88 89 else if(extTag[0].equals("#EXT-X-STREAM-INF"))
89 90 {
90   - /*EXTXSTREAM=1
91   - PROGRAMID=""
  91 + expectList = true;
  92 + /*PROGRAMID=""
92 93 CODECS=""
93 94 RESOLUTION=""
94 95 ARGUMENTS=`echo $line | cut -d':' -f 2`
... ...
src/com/upc/pbe/upcnews/Playlist.java
1   -package com.upc.pbe.upcnews;
2   -
3   -public class Playlist
4   -{
5   - private SegmentList segmentList;
6   -
7   - public Playlist()
8   - {
9   - segmentList = new SegmentList();
10   - }
11   -
12   -}