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 |
Tags
- 코틀린
- Java
- Kotlin
- JavaScript
- npm
- 랜덤번호
- JS
- TypeScript
- scrollview
- React
- GoogleMaps
- fragment
- Android
- 안드로이드
- 스프링부트
- 랜덤넘버
- Javscript
- SpringBoot
- Hook
- TextView
- 자바스크립트
- Linux
- RecyclerView
- array
- 리액트
- stylesheet
- 오버라이딩
- nodejs
- 구글맵스
- button
Archives
- Today
- Total
타닥타닥 개발자의 일상
Kotlin 안드로이드 화면에 videoView이용해 동영상 삽입하기 본문
파일 및 폴더 구성
raw 폴더 생성하고 music.mp4 동영상(혹은 자신이 원하는 동영상) 삽입.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<VideoView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/videoView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.kt
package com.example.sample21
import android.net.Uri
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.MediaController
import android.widget.VideoView
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val videoView = findViewById<VideoView>(R.id.videoView)
videoView.setMediaController(MediaController(this))
//videoView에 MediaController연결
videoView.setVideoURI(Uri.parse("android.resource://" + packageName + "/"+R.raw.music))
//resource 폴더 안 raw 폴더 안에 있는 music이라는 동영상 연결
}
}
결과화면
'코딩 기록 > Kotlin' 카테고리의 다른 글
Kotlin Fragment 기능 이용해서 안드로이드 화면에 상단 메뉴 만들고 선택에 따라서 화면전환 하기 (1) | 2022.02.07 |
---|---|
Kotlin 안드로이드 화면에 WebView이용해서 html 문서 연결하고 구현화면 버튼 클릭시 알림창 띄우기 (0) | 2022.02.07 |
Kotlin 정렬된 grid 안드로이드 화면에 표시하기, grid에서 선택한 사항 textview랑 연결하기 (0) | 2022.02.07 |
ScrollView / TableLayout 이용하여 스크롤 가능한 안드로이드 화면 만들기 (0) | 2022.02.07 |
Kotlin / listview 이용해서 android화면에 스크롤 사용하는 긴 선택항목 만들기 (0) | 2022.02.07 |
Comments