Ijkplayer视频播放

来源:互联网 发布:吉林11选5数据遗漏 编辑:程序博客网 时间:2024/06/14 00:07
先到依赖
compile 'com.github.leifzhang:IjkLib:0.4.3'网络权限
<uses-permission android:name="android.permission.INTERNET" />
android:configChanges="orientation|keyboardHidden"android:screenOrientation="sensorLandscape"

布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="com.example.cll.caolilu1508b20171117.Ijkplayer">    <tv.danmaku.ijk.media.widget.media.IjkVideoView        android:layout_width="match_parent"        android:layout_height="match_parent"        android:id="@+id/view_video">    </tv.danmaku.ijk.media.widget.media.IjkVideoView></LinearLayout>
播放视频代码
package com.example.cll.caolilu1508b20171117;import android.content.pm.ActivityInfo;import android.content.res.Configuration;import android.net.Uri;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import tv.danmaku.ijk.media.player.IjkMediaPlayer;import tv.danmaku.ijk.media.widget.media.AndroidMediaController;import tv.danmaku.ijk.media.widget.media.IjkVideoView;public class Ijkplayer extends AppCompatActivity {    private IjkVideoView mViewVideo;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_ijkplayer);        initView();    //    mViewVideo.setAspectRatio(IRenderView.AR_ASPECT_FIT_PARENT)        AndroidMediaController controller = new AndroidMediaController(this, false);        mViewVideo.setMediaController(controller);        String url = "https://wdl.wallstreetcn.com/41aae4d2-390a-48ff-9230-ee865552e72d";        mViewVideo.setVideoURI(Uri.parse(url));        mViewVideo.start();    }    private void initView() {        mViewVideo = (IjkVideoView) findViewById(R.id.view_video);    }    private void setOrientation(int orientation) {        if (orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);        } else {            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);        }    }    @Override    public void onConfigurationChanged(Configuration newConfig) {        super.onConfigurationChanged(newConfig);    }    @Override    protected void onPause() {        super.onPause();        mViewVideo.pause();    }    @Override    protected void onDestroy() {        super.onDestroy();        IjkMediaPlayer.native_profileEnd();    }    @Override    protected void onResume() {        super.onResume();        mViewVideo.resume();    }}