dpi
dpi =√(horizontal²+vertical²)/diagonal 屏幕分辨率(px) 屏幕大小(英寸)
DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);//获取屏幕尺寸信息 currnetDensity = (int)( metrics.density * 160 );//dpi
2017/11/10 01:07 明天继续看
ijkplayer 介绍http://blog.csdn.net/u010987039/article/details/52301077
分割线————————————————————————————————————————————————————
package com.example.jay.com.trtsp; import android.content.Context; import android.media.MediaPlayer; import android.os.Bundle; import android.os.SystemClock; import android.provider.Settings; import android.support.annotation.NonNull; import android.support.annotation.StringDef; import android.support.design.widget.BottomNavigationView; import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; import android.view.View; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Button; import android.widget.Toast; import android.os.Handler; import android.app.Activity; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.widget.MediaController; import android.widget.VideoView; import android.graphics.Bitmap; import android.view.KeyEvent; import android.view.ViewGroup; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.webkit.JavascriptInterface; import android.view.ViewGroup.LayoutParams; import android.util.DisplayMetrics; import javax.xml.transform.ErrorListener; public class MainActivity extends AppCompatActivity { private TextView mTextMessage; private VideoView videoView ; private Handler handler=null; private Context context; private Button btn; WebView mwebView; WebSettings mWebSettings; TextView beginLoading,endLoading,loading,mtitle; private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.navigation_home: mTextMessage.setText(R.string.title_home); return true; case R.id.navigation_dashboard: mTextMessage.setText(R.string.title_dashboard); return true; case R.id.navigation_notifications: mTextMessage.setText(R.string.title_notifications); return true; } return false; } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mwebView = (WebView) findViewById(R.id.webView1); beginLoading = (TextView) findViewById(R.id.text_beginLoading); endLoading = (TextView) findViewById(R.id.text_endLoading); loading = (TextView) findViewById(R.id.text_Loading); mtitle = (TextView) findViewById(R.id.title); btn = (Button) findViewById(R.id.button); handler=new Handler(); //初始化videobox隐藏 final VideoView videoView = (VideoView)findViewById(R.id.videoView); // videoView.setlistener LinearLayout videoBox = (LinearLayout)findViewById(R.id.videoBox); LayoutParams videoBoxStyle = videoBox.getLayoutParams(); LinearLayout webViewBox = (LinearLayout) findViewById(R.id.webViewBox); LayoutParams webViewBoxStyle = webViewBox.getLayoutParams(); videoBox.setVisibility(View.GONE); webViewBox.setVisibility(View.VISIBLE); // videoBoxStyle.width=0; // videoBoxStyle.height=0; // 加载video控制器 // videoView.setMediaController(new MediaController(this)); videoView.setOnInfoListener(new MediaPlayer.OnInfoListener() { @Override public boolean onInfo(MediaPlayer mp, int what, int extra) { System.out.println(what); System.out.println(extra); return true; // return false; } }); // webview相关设置 mWebSettings = mwebView.getSettings(); // mwebView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS); mwebView.getSettings().setJavaScriptEnabled(true); // mwebView.getSettings().setRenderPriority(RenderPriority.HIGH); mwebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); //设置 缓存模式 // 开启 DOM storage API 功能 mwebView.getSettings().setDomStorageEnabled(true); //开启 database storage API 功能 mwebView.getSettings().setDatabaseEnabled(true); //开启 Application Caches 功能 mwebView.getSettings().setAppCacheEnabled(true); mwebView.getSettings().setBlockNetworkImage(false); mwebView.getSettings().setLoadsImagesAutomatically(true); //自动加载图片 mwebView.getSettings().setAllowUniversalAccessFromFileURLs(true);// // mwebView.getSettings().setPluginState(PluginState.OFF); // 获取屏幕相关信息 DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); // webview导入需要显示的html文件 mwebView.loadUrl("file:///android_asset/newdemo/index.html"); // 添加js接口 mwebView.addJavascriptInterface(new StartVideo(), "jsInterface"); //设置不用系统浏览器打开,直接显示在当前webView mwebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); System.out.println(mwebView); view.loadUrl(url); return true; } }); //设置WebChromeClient类 mwebView.setWebChromeClient(new WebChromeClient() { //获取网站标题 @Override public void onReceivedTitle(WebView view, String title) { System.out.println("标题在这里"); // mtitle.setText(title); } //获取加载进度 @Override public void onProgressChanged(WebView view, int newProgress) { System.out.println("这里是加载进度"+newProgress); } }); //设置webViewClient类 mwebView.setWebViewClient(new WebViewClient() { //设置加载前的函数 @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { System.out.println("开始加载了"); // beginLoading.setText("开始加载了"); } //设置结束加载函数 @Override public void onPageFinished(WebView view, String url) { // endLoading.setText("结束加载了"); // addVideoListner(); } }); } //点击返回上一页面而不是退出浏览器 @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && mwebView.canGoBack()) { mwebView.goBack(); return true; } return super.onKeyDown(keyCode, event); } //销毁webView @Override protected void onDestroy() { if (mwebView != null) { mwebView.loadDataWithBaseURL(null, "", "text/html", "utf-8", null); mwebView.clearHistory(); ((ViewGroup) mwebView.getParent()).removeView(mwebView); mwebView.destroy(); mwebView = null; } super.onDestroy(); } // 播放、停止视频功能 private final class StartVideo { private Context context; @JavascriptInterface public void showToast(String text){ Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show(); } @JavascriptInterface public void showJsText(final String text){ runOnUiThread(new Runnable() { @Override public void run() { mwebView.loadUrl("javascript:jsText('"+text+"')"); } }); } @JavascriptInterface public void openVideo(String text) { final String thisText = text; handler.post(new Runnable() { @Override public void run() { Button btn = (Button)findViewById(R.id.button); // LayoutParams btnStyle = btn.getLayoutParams(); final VideoView videoView = (VideoView)findViewById(R.id.videoView); videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { videoView.start(); } }); // LayoutParams videoStyle = videoView.getLayoutParams(); final LinearLayout videoBox = (LinearLayout)findViewById(R.id.videoBox); final LayoutParams videoBoxStyle = videoBox.getLayoutParams(); final LinearLayout webViewBox = (LinearLayout) findViewById(R.id.webViewBox); final LayoutParams webViewBoxStyle = webViewBox.getLayoutParams(); final DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); System.out.println("这里是获取的屏幕信息"+metrics); //video展示,webview隐藏 // videoBoxStyle.width=(int)metrics.density*360; // videoBoxStyle.height=(int)metrics.density*640; // webViewBoxStyle.width=0; // webViewBoxStyle.height=0; webViewBox.setVisibility(View.GONE); videoBox.setVisibility(View.VISIBLE); // videoView.setOnErrorListener(); // videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { // @Override // public void onCompletion(MediaPlayer videoView) { // // } // }); String url = thisText; Uri uri = Uri.parse(url); videoView.setVideoURI(uri); videoView.requestFocus(); videoView.start(); // videoView.resume(); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { System.out.println("stop"); // videoBoxStyle.width=0; // videoBoxStyle.height=0; videoBox.setVisibility(View.GONE); webViewBox.setVisibility(View.VISIBLE); System.out.println(videoBox); System.out.println(videoBoxStyle.width); // webViewBoxStyle.width=(int)metrics.density*360; // webViewBoxStyle.height=(int)metrics.density*640; System.out.println(webViewBox); System.out.println(webViewBoxStyle.width); videoView.stopPlayback(); } }); Toast.makeText(getApplicationContext(), thisText, Toast.LENGTH_SHORT).show(); // Toast.makeText(getApplicationContext(),, Toast.LENGTH_SHORT).show(); // 需要请求获取视频流地址 // videoView.setVideoPath("rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov"); // dp px的转换 // videoStyle.width=(int)metrics.density*314; // videoStyle.height=(int)metrics.density*176; // btnStyle.width=(int)metrics.density*123; // btnStyle.height =(int)metrics.density*67; // videoView.setMediaController(new MediaController(this.)); // videoView.setVisibility(View.VISIBLE); // webViewStyle.width=0; // webViewStyle.height=0; // webView.setVisibility(View.INVISIBLE); } }); } @JavascriptInterface public void stopVideo(){ handler.post(new Runnable() { @Override public void run() { LinearLayout videoBox = (LinearLayout)findViewById(R.id.videoBox); LayoutParams videoBoxStyle = videoBox.getLayoutParams(); LinearLayout webViewBox = (LinearLayout) findViewById(R.id.webViewBox); LayoutParams webViewBoxStyle = videoBox.getLayoutParams(); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); videoView.stopPlayback(); videoBoxStyle.width=0; videoBoxStyle.width=0; // videoView.setVisibility(View.INVISIBLE); webViewBoxStyle.width=(int)metrics.density*360; webViewBoxStyle.height=(int)metrics.density*640; } }); } } // private int convertDpToPixel(int dp) { // DisplayMetrics displayMetrics = this.context.getResources().getDisplayMetrics(); // return (int)(dp*displayMetrics.density); // } // // private int convertPixelToDp(int pixel) { // DisplayMetrics displayMetrics = this.context.getResources().getDisplayMetrics(); // return (int)(pixel/displayMetrics.density); // } }
http://blog.csdn.net/xipiaoyouzi/article/details/75315836?locationNum=4&fps=1
android vlc