在Android应用程序无法使用jwplayer [英] Cannot use jwplayer in an Android app

查看:264
本文介绍了在Android应用程序无法使用jwplayer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个Android应用程序,我想从一个URL动态播放一些视频。所以我把布局中的Web视图并查看其中包含jwplayer code,但jwplayer是不是有一个HTML文件和Web视图只显示正在载入播放器......。我不明白的地方的问题。

I am developing an Android application where I want to play some video dynamically from a URL. So I put a web view in layout and view a html file which contains the jwplayer code but jwplayer is not there, and the web view is showing only "Loading the player....". I can not understand where the issue is.

VideoView code 此处

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class VideoActivity extends Activity {
/** Called when the activity is first created. */
WebView sampleWeb;
String htmlText;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.web);

    sampleWeb=(WebView)findViewById(R.id.webView);
    WebSettings webSettings=sampleWeb.getSettings();

    sampleWeb.getSettings().setJavaScriptEnabled(true);
    sampleWeb.getSettings().setBuiltInZoomControls(false);

    sampleWeb.getSettings().setLoadsImagesAutomatically(true);

    sampleWeb.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    sampleWeb.getSettings().setAllowFileAccess(true);
    sampleWeb.getSettings().setPluginsEnabled(true);
    sampleWeb.setWebViewClient(new WebViewClient());


  //  sampleWeb.loadUrl("m.google.com");
    htmlText="<!DOCTYPE html> ";
    htmlText+="<html lang='en'>";
    htmlText+="<head><meta charset='utf-8'>";

    htmlText+="</head>";
    htmlText+="<body style='margin:0; pading:0;background-color: #ffffff;'>";
    htmlText+="<div style='color:black'>Loading the player ...</div>";
    htmlText+="<script type='text/javascript' src='http://shourav.com/android/jwplayer.min.js'></script>";

    htmlText+="<div id='mediaspace'>This text will be replaced</div>";

    htmlText+="<script type='text/javascript'>";
    htmlText+="jwplayer('mediaspace').setup({";
    htmlText+="'flashplayer': 'http://developer.longtailvideo.com/svn/trunk/fl5/player.swf',";
    htmlText+="'file': 'http://shourav.com/android/android.MP4',";
   // htmlText+="'streamer': 'rtmp://b27i9s9t3.rtmphost.com/AndroidMedia',";
    htmlText+="'controlbar': 'bottom',";
    htmlText+="'width': '200',";
    htmlText+="'height': '150'";
    htmlText+="});";
    htmlText+="</script>";

    htmlText+="</body>";
    sampleWeb.loadData(htmlText, "text/html", "utf-8");

}

}

推荐答案

ü可以参考下code和做it..i希望这个例子帮助ü要摆脱这种..

U can refer below code and do it..i hope this example help u to out of this..

 private void createVideoHtml(File flvDirectory, File htmlFile, String videofilename)
{
    String htmlPre = "<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"></head><body style='margin:0; padding:0;'>";  
    String htmlCode =
            "<script type='text/javascript' src='"+ flvDirectory.getAbsolutePath() + "/jwplayer.js'></script>" +
            "<div id='mediaspace'>EZ Stream TV FLV Player</div>" +
            "<script type='text/javascript'>" +
            "jwplayer('mediaspace').setup({" +
            "'flashplayer': '"+ flvDirectory.getAbsolutePath() + "/player.swf', 'file': '" + videofilename + "', 'backcolor': 'FFFFFF', 'frontcolor': '000000', 'lightcolor': '000000'," +
            "'screencolor': '000000', 'volume': '100', 'autostart': 'true', 'mute': 'false', 'quality': 'false', 'controlbar': 'bottom', 'width': '100%', 'height': '100%'," +
            "events: { " +
            "onComplete: function() { alert('COMPLETED');}" +
            "}});" +
            "</script>";
    String htmlPost = "</body></html>";
    String finalHTML = htmlPre + htmlCode + htmlPost;

    try {
        FileWriter f = new FileWriter(htmlFile);
        PrintWriter p = new PrintWriter(f);
        p.print(finalHTML);
        p.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

webView = (WebView)findViewById(R.id.web_player);
    webView.getSettings().setBuiltInZoomControls(false);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setLoadsImagesAutomatically(true);
    webView.getSettings().setPluginsEnabled(true);
    webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    webView.getSettings().setAllowFileAccess(true);
    webView.setInitialScale(60);
    webView.setBackgroundColor(Color.BLACK);
    getWindow().addFlags(128);
    webView.getSettings().setUserAgentString("Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)");
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

    webView.setWebChromeClient(new WebChromeClient() {  
        @Override  
        public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result)  
        {  
            Log.d(TAG, message);
            new AlertDialog.Builder(view.getContext()).setMessage(message).setCancelable(true).show();
            result.confirm();
            return true;
        }
    });

这篇关于在Android应用程序无法使用jwplayer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆