Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- 마스크 효과 #안드로이드 프로그래밍
- 안드로이드 앱개발.
- 안드로이드 #데이터베이스 #안드로이드 앱프로그래밍
- #안드로이드 스튜디오 #안드로이드 앱개발 #안드로이드 카드뷰
- 안드로이드 스튜디오
- #안드로이드 앱프로그래밍
- 안드로이드
- #안드로이드 #안드로이드 앱 프로그래밍 #모바일 개발자
- #안드로이드 프로그래밍
- #안드로이드 #안드로이드 앱프로그래밍 #모바일 개발 #키패드 제어하기
Archives
- Today
- Total
모바일 개발을 잘하고 싶은 안드로이드 앱개발자
동영상 재생하는 앱만들기 본문
activity_main.xml
<?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"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="재생하기" />
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
LinearLayiyt(vertical)로 변경합니다.그리고 '재생하기'라는 글자가 표시된 한 개의 버튼과 ViderView위젯을 추가합니다
레이아웃에 추가한 비디오뷰 객체를 자바 소스코드애서 참조한 후 동영상 파일의 위치를 setVideoURL메서드로 지정하기만 하면 동영상을 재생할 수 있습니다.
MainActivity.java
package org.techtown.video.player;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.VideoView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
public static final String VIDEO_URL = "https://sites.google.com/site/ubiaccessmobile/sample_video.mp4";
VideoView videoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView = findViewById(R.id.videoView);
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
Button button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
videoView.setVideoURI(Uri.parse(VIDEO_URL));
videoView.requestFocus();
videoView.start();
}
});
}
}
동영상의 재생 상태를 보거나 도영상 제어할 떄 사용되는 미디어컨트롤러(MediaController)객체는setMediaControkker메서드로 설정할 수 있는 데 손가락으로 터치하면 컨트롤러 부분을 보여주게 됩니다.비디오 뷰 객체에는 getDuration이나pause와 같이 동영상을 제어하는 데 필요한 다른 메서드들도 정의되어 있습니다.MediaController클래스는android.widger을 선택하여 추가 하세요.