SoundPool + ViedeoView

SoundPool + ViedeoView

new SoundPool (up to play some more, andio full man, Music (playing type), voice)
the above mentioned id = the Load (context, resource id, priority)
stream id = play (voice id, the left channel, right channel volume priority, cycle, play type)
play () playback
stop () stops
pause () pause

VideoView // used to play video

Setting controller
setMediaColltollerCnewMediaColl (context object)
setVideoVril (Uri URI) // set the playback source
requestFocus () // get the focus screen during playback
start () Starts

Mediaplayer related
player.prepare () and player.prepareAsync ()
two methods may be loaded into memory resource, the first method is suitable for loading a
file resource or network resource

ViedeoView Code

  Button button1;
    Button button2;
    Button button3;
    VideoView videoView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        button1=findViewById(R.id.bofang);
        button2=findViewById(R.id.zanting);
        button3=findViewById(R.id.tingzhi);
        videoView=findViewById(R.id.video);
        button1.setOnClickListener(this);
        button2.setOnClickListener(this);
        button3.setOnClickListener(this);


        videoView.setMediaController(new MediaController(this));
        Uri uri = Uri.parse("http://vfx.mtime.cn/Video/2019/02/04/mp4/190204084208765161.mp4");
        videoView.setVideoURI(uri);
        videoView.requestFocus();
        videoView.start();

    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id) {
            case R.id.bofang:
                Log.e("####","bofang");
                videoView.start();
                break;
            case R.id.zanting:
                Log.e("####","zanting");
                videoView.pause();
                break;
            case R.id.tingzhi:
                videoView.stopPlayback();
                videoView.resume();
                Log.e("####","tingzhi");
                break;
            default:
                break;
        }
    }

SoundPool Code

  SoundPool soundPool;
    Button play;
    Button stop;
    Button pause;
    int load;
    int load1;

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


        initPool();
        play = findViewById(R.id.pool_start);
        stop = findViewById(R.id.pool_stop);
        pause = findViewById(R.id.pool_pause);

    }

    private void initPool() {
        soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);

        load = soundPool.load(this, R.raw.jiuer, 1);

        load1 = soundPool.load(this, R.raw.river, 1);
        if (load <= 0) {
            Log.e("error", "load error");
            finish();
        }
    }

    public void onClickBtn(View view) {

        int id = view.getId();
        switch (id) {
            case R.id.pool_pause:
                soundPool.pause(load1);
                break;
            case R.id.pool_start:
                load=soundPool.play(load, 1.0f, 1.0f, 1, 0, 1.0f);
                load1=soundPool.play(load1,1.0f, 1.0f, 1, 0, 1.0f);
                break;
            case R.id.pool_stop:
                soundPool.pause(load);
//                soundPool.release();
                break;
            default:
                break;
        }

    }

Guess you like

Origin blog.csdn.net/weixin_45038475/article/details/92010548