İlkin Manifest dosyasına aşağıdaki izinler eklenir
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
- <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Ardından layout dosyasına aşağıdaki kod eklenir
- <?xml version="1.0" encoding="utf-8"?>
- <android.support.constraint.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="example.javatpoint.com.kotlinvideoplayer.MainActivity">
- <FrameLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
- <VideoView
- android:id="@+id/videoView"
- android:layout_width="wrap_content"
- android:layout_height="308dp"
- android:layout_marginBottom="0dp"
- android:layout_marginEnd="0dp"
- android:layout_marginStart="0dp"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintHorizontal_bias="0.0"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- app:layout_constraintVertical_bias="1.0" />
- </FrameLayout>
- </android.support.constraint.ConstraintLayout>
Ardından Main Actity aşağıdaki şekle çevrilir
Üsttte kendi packet isminin altına şunları yapıştır
- import android.net.Uri
- import android.net.Uri.*
- import android.support.v7.app.AppCompatActivity
- import android.os.Bundle
- import android.os.Environment
- 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)
- //Creating MediaController
- val mediaController = MediaController(this)
- mediaController.setAnchorView(videoView)
- //specify the location of media file
- val uri:Uri = parse(Environment.getExternalStorageDirectory().getPath() + "/Movies/video.mp4")
- //Setting MediaController and URI, then starting the videoView
- videoView.setMediaController(mediaController)
- videoView.setVideoURI(uri)
- videoView.requestFocus()
- videoView.start()
- }
- }
Hiç yorum yok:
Yorum Gönder