앱만들기.32(VideoView)

비디오는 가로로 보니까

 

Landscape!

 

videoview검색

 

 

잡아댕겨서풀스크린 해주고

width와 height를 match로 바꿔주면 풀스크린 모드 됨

 

권한주기

<uses-permission android:name="android.permission.INTERNET"/>

헤더 안보이게

<activity android:name=".MainActivity"
android:screenOrientation="landscape"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">

 

 

 

setAnchorView 가 뭘까?

Set the view that acts as the anchor for the control view.

라고 공식사이트에 써있는것으로 보아.

컨트롤 뷰의 앵커역할을 하는 뷰임을 알 수 있다.

그럼 앵커는뭘까?

Anchor는 자식뷰들간의 연관성을 표현하는 개념이라고 한다.

여기서 컨트롤은 위젯을 말한다.

즉, 위젯 뷰를 연관시키는 뷰임을 알 수 있따.

 

main.js

package com.example.videoviewexample;

import androidx.appcompat.app.AppCompatActivity;

import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class MainActivity extends AppCompatActivity {

    private VideoView videoView; //비디오를 실행할 수 있게 도와주는 뷰
    private MediaController mediaController; //재생,정지버튼 등 미디어 제어버튼부 관리
    private String videoURL = "https://www.radiantmediaplayer.com/media/bbb-360p.mp4";


    @Override
    protected void onCreate(Bundle savedInstanceState) { //앱이 첫 실행이 되었을때 수행한다. 생명주기중 일종
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        videoView = findViewById(R.id.videoView); //비디오뷰 아이디 연결
        mediaController = new MediaController(this);
        mediaController.setAnchorView(videoView);
        Uri uri = Uri.parse(videoURL);
        videoView.setMediaController(mediaController); // 비디오뷰에 미디어컨트롤러(미디어 제어 버튼부)를 세팅
        videoView.setVideoURI(uri); //비디오 뷰의 주소를 설정
        videoView.start();//비디오 실행



    }
}

manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.videoviewexample">

    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.VideoViewExample">
        <activity android:name=".MainActivity"
            android:screenOrientation="landscape"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".MainActivity">

    <VideoView
        android:id="@+id/videoView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

 

결과:

 

오류발생

아니 이게 웬걸, 동영상 재생이 불가하단다.

https://lcw126.tistory.com/117

 

이걸참고했다.

mainjava에 추가

//화면에 안보일때...
    @Override
    protected void onPause() {
        super.onPause();

        //비디오 일시 정지
        if(videoView!=null && videoView.isPlaying()) videoView.pause();
    }
    //액티비티가 메모리에서 사라질때..
    @Override
    protected void onDestroy() {
        super.onDestroy();
        //
        if(videoView!=null) videoView.stopPlayback();
    }

manifest에 추가해주기

android:usesCleartextTraffic="true"

android:usesCleartextTraffic:

앱이 일반 텍스트 HTTP와 같은 일반 텍스트 네트워크 트래픽을 사용하는지 여부를 나타낸다.

 

 

동영상 서비스가 종료되어 해당 콘텐츠를 재생할 수 없습니다.

자알된다~~