编译器:android studio(语言:java)

(源代码已上传Github--GitHub - caip1299920300/movie_android: 安卓网络视频播放器

1.在app的build.gradle中添加

implementation 'cn.jzvd:jiaozivideoplayer:7.7.0'
implementation 'com.google.code.gson:gson:2.2.4'
implementation 'com.squareup.picasso:picasso:2.5.2'

 2.在AndroidManifest.xml中添加

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
android:usesCleartextTraffic="true"

 3.在activity_main.xml添加

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <cn.jzvd.JzvdStd
        android:id="@+id/item_main_jzvd"
        android:layout_width="match_parent"
        android:layout_height="220dp">
    </cn.jzvd.JzvdStd>
</LinearLayout>

4.在MainActivity.java添加


import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.squareup.picasso.Picasso;

import cn.jzvd.Jzvd;
import cn.jzvd.JzvdStd;

public class MainActivity extends AppCompatActivity {

    JzvdStd jzvdStd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        jzvdStd = findViewById(R.id.item_main_jzvd);

        String path = "https://vd4.bdstatic.com/mda-kfmi6042m94u0pdb/sc/mda-kfmi6042m94u0pdb.mp4?v_from_s=hkapp-haokan-hnb&auth_key=1661067006-0-0-7ab874e96fe8497734042bc7a3e6820b&bcevod_channel=searchbox_feed&pd=1&cd=0&pt=3&logid=0006206421&vid=5195914434946548038&abtest=103579_1&klogid=0006206421";
        jzvdStd.setUp(path,"test",JzvdStd.SCREEN_NORMAL);
        Picasso.with(this).
              load("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fy.gtimg.cn%2Fmusic%2Fphoto_new%2FT023R750x750M000001n4xOm0umd79.jpg%3Fmax_age%3D2592000&refer=http%3A%2F%2Fy.gtimg.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1663657261&t=71176fd951c489550b65b2f9eb5e1f29").
                into(jzvdStd.posterImageView);
        jzvdStd.positionInList = 0;

    }

    @Override
    protected void onPause() {
        super.onPause();
        Jzvd.goOnPlayOnPause();
    }

    @Override
    public void onBackPressed() {
        if (Jzvd.backPress()) {
            return;
        }
        super.onBackPressed();
    }

    @Override
    protected void onResume() {
        super.onResume();
        Jzvd.goOnPlayOnResume();
    }

        @Override
    protected void onStop() {
        super.onStop();
        JzvdStd.releaseAllVideos();    //释放正在被播放的视频信息
    }
}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐