Widevine sample player

For bug 4245169

Change-Id: Ie110d5603f19cd54878d2c4506e8ffad11207f10
This commit is contained in:
Gloria Wang
2011-04-06 10:28:00 -07:00
parent 1445a4288d
commit fc6f6134e9
46 changed files with 2011 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
/*
* (c)Copyright 2011 Widevine Technologies, Inc
*/
package com.widevine.demo;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import android.sax.Element;
import android.sax.EndElementListener;
import android.sax.EndTextElementListener;
import android.sax.RootElement;
import android.util.Xml;
/**
* Parser for the XML configuration file that defines the assets available to
* play
*/
public class ConfigXMLParser {
private URL mFeedUrl;
private InputStream inputStream;
protected InputStream getInputStream() {
try {
if (inputStream != null)
return inputStream;
else
return mFeedUrl.openConnection().getInputStream();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public ConfigXMLParser(URL feedUrl) {
mFeedUrl = feedUrl;
}
public ConfigXMLParser(InputStream inputStream) {
this.inputStream = inputStream;
}
public List<AssetDescriptor> parse() {
final AssetDescriptor currentAssetDescriptor = new AssetDescriptor();
RootElement root = new RootElement("widevine");
final List<AssetDescriptor> assetDescriptors = new ArrayList<AssetDescriptor>();
Element assetlist = root.getChild("asset-list");
Element asset = assetlist.getChild("asset");
asset.setEndElementListener(new EndElementListener() {
public void end() {
if (currentAssetDescriptor.getUri().indexOf("http") != -1
&& (currentAssetDescriptor.getUri().indexOf(".wvm") != -1
|| !currentAssetDescriptor.getUri().substring(currentAssetDescriptor
.getUri().lastIndexOf("/")).contains("."))) {
assetDescriptors.add(currentAssetDescriptor.copy());
}
}
});
asset.getChild("title").setEndTextElementListener(new EndTextElementListener() {
public void end(String body) {
currentAssetDescriptor.setTitle(body);
}
});
asset.getChild("uri").setEndTextElementListener(new EndTextElementListener() {
public void end(String body) {
currentAssetDescriptor.setUri(body);
}
});
asset.getChild("description").setEndTextElementListener(new EndTextElementListener() {
public void end(String body) {
currentAssetDescriptor.setDescription(body);
}
});
asset.getChild("thumbnail").setEndTextElementListener(new EndTextElementListener() {
public void end(String body) {
currentAssetDescriptor.setThumbnail(body);
}
});
try {
Xml.parse(this.getInputStream(), Xml.Encoding.UTF_8, root.getContentHandler());
} catch (Exception e) {
throw new RuntimeException(e);
}
return assetDescriptors;
}
}