Reputation: 437
Aparat is an online video service like youtube, I want to know how can I show one of the videos in my application ? For example I want to show this video, but not the whole page, just the video . How can i do that ?
Thanks in advance .
Upvotes: -1
Views: 1477
Reputation: 798
Finally I do this job! loading aparat videos in my android app. just follow below steps: First, you need this java class:
public class WebVideoView {
private String url;
private Context context;
private WebView webview;
private static final String HTML_TEMPLATE = "webvideo.html";
public CWebVideoView(Context context, WebView webview) {
this.webview = webview;
this.context = context;
webview.setBackgroundColor(0);
webview.getSettings().setJavaScriptEnabled(true);
}
public void load(String url){
this.url = url;
String data = readFromfile(HTML_TEMPLATE, context);
data = data.replace("%1", url);
webview.loadData(data, "text/html", "UTF-8");
}
public String readFromfile(String fileName, Context context) {
StringBuilder returnString = new StringBuilder();
InputStream fIn = null;
InputStreamReader isr = null;
BufferedReader input = null;
try {
fIn = context.getResources().getAssets().open(fileName, Context.MODE_WORLD_READABLE);
isr = new InputStreamReader(fIn);
input = new BufferedReader(isr);
String line = "";
while ((line = input.readLine()) != null) {
returnString.append(line);
}
} catch (Exception e) {
e.getMessage();
} finally {
try {
if (isr != null)
isr.close();
if (fIn != null)
fIn.close();
if (input != null)
input.close();
} catch (Exception e2) {
e2.getMessage();
}
}
return returnString.toString();
}
public void reload() {
if (url!=null){
load(url);
}
}
}
Second, in assets folder create WebVideo.html file and paste the following codes in it:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style>
iframe { border: 0; position:fixed; width:100%; height:100%; bgcolor="#000000"; }
body { margin: 0; bgcolor="#000000"; }
</style>
</head>
<body>
<iframe src="%1" frameborder="0" allowfullscreen></iframe>
</body>
</html>
Then, in your layout that you want to show the video add this view:
<WebView
android:id="@+id/video"
android:visibility="gone"
android:background="#000000"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Finally, in your activity define your view like below codes and replace the url that you want to show in your activity with the url in load method(last line):
WebView videoView = (WebView) this.findViewById(R.id.video);
videoView.setVisibility(View.VISIBLE);
WebVideoView webVideoView = new CWebVideoView(this, videoView);
webVideoView.load("url");
Enjoy your videos :)
there is a point that in url, you should insert iframe code that it is available in aparat website for each video below it. ;)
Upvotes: 3
Reputation: 1494
I'm not familiar with that service but from the link you provided I was able to get the following embed html:
<iframe src="http://www.aparat.com/video/video/embed/videohash/d8wFA/vt/frame" allowFullScreen="true" webkitallowfullscreen="true" mozallowfullscreen="true" height="360" width="640" ></iframe>
So one way to do it that I was able to get working in a quick standalone app is to just put that into a webview:
String videoEmbedHtml = "<iframe src=\"http://www.aparat.com/video/video/embed/videohash/d8wFA/vt/frame\" allowFullScreen=\"true\" webkitallowfullscreen=\"true\" mozallowfullscreen=\"true\" height=\"360\" width=\"640\" ></iframe>";
webView.getSettings().setJavaScriptEnabled(true);
webView.loadData(videoEmbedHtml, "text/html", "utf-8");
Alternatively you could find out if these guys have an Android SDK.
Upvotes: 0