activity_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="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
----------------------------
----------------------------
MainActivity.java
package com.example.videoview;
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 = "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.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(); // 비디오 실행
}
}
----------------------------
----------------------------
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.videoview">
<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/AppTheme"
android:usesCleartextTraffic="true"> <!-- 이 코드가 있어야 http 주소를 불러옴 -->
<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>
----------------------------
'안드로이드 앱 만들기' 카테고리의 다른 글
Firebase Recycler View (0) | 2020.09.12 |
---|---|
Constraint Layout (0) | 2020.09.10 |
BroadCastReceiver (0) | 2020.09.07 |
RelativeLayout (랠러티브레이아웃) (0) | 2020.09.06 |
Login & Register (0) | 2020.09.02 |