Kotlin Video Player

İlkin Manifest dosyasına aşağıdaki izinler eklenir


  1. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>  
  2. <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>  
Ardından layout dosyasına aşağıdaki kod eklenir
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:app="http://schemas.android.com/apk/res-auto"  
  4.     xmlns:tools="http://schemas.android.com/tools"  
  5.     android:layout_width="match_parent"  
  6.     android:layout_height="match_parent"  
  7.     tools:context="example.javatpoint.com.kotlinvideoplayer.MainActivity">  
  8.   
  9.     <FrameLayout  
  10.         android:layout_width="match_parent"  
  11.         android:layout_height="wrap_content">  
  12.   
  13.         <VideoView  
  14.             android:id="@+id/videoView"  
  15.             android:layout_width="wrap_content"  
  16.             android:layout_height="308dp"  
  17.             android:layout_marginBottom="0dp"  
  18.             android:layout_marginEnd="0dp"  
  19.             android:layout_marginStart="0dp"  
  20.             app:layout_constraintBottom_toBottomOf="parent"  
  21.             app:layout_constraintEnd_toEndOf="parent"  
  22.             app:layout_constraintHorizontal_bias="0.0"  
  23.             app:layout_constraintStart_toStartOf="parent"  
  24.             app:layout_constraintTop_toTopOf="parent"  
  25.             app:layout_constraintVertical_bias="1.0" />  
  26.     </FrameLayout>  
  27. </android.support.constraint.ConstraintLayout>  



Ardından Main Actity aşağıdaki şekle çevrilir
Üsttte kendi packet isminin altına şunları yapıştır
  1. import android.net.Uri  
  2. import android.net.Uri.*  
  3. import android.support.v7.app.AppCompatActivity  
  4. import android.os.Bundle  
  5. import android.os.Environment  
  6. import android.widget.MediaController  
  7. import android.widget.VideoView  
  8.   
  9. class MainActivity : AppCompatActivity() {  
  10.   
  11.     override fun onCreate(savedInstanceState: Bundle?) {  
  12.         super.onCreate(savedInstanceState)  
  13.         setContentView(R.layout.activity_main)  
  14.   
  15.         val videoView = findViewById<VideoView>(R.id.videoView)  
  16.         //Creating MediaController  
  17.         val mediaController = MediaController(this)  
  18.         mediaController.setAnchorView(videoView)  
  19.         //specify the location of media file  
  20.         val uri:Uri = parse(Environment.getExternalStorageDirectory().getPath() + "/Movies/video.mp4")  
  21.         //Setting MediaController and URI, then starting the videoView  
  22.         videoView.setMediaController(mediaController)  
  23.         videoView.setVideoURI(uri)  
  24.         videoView.requestFocus()  
  25.         videoView.start()  
  26.     }  
  27. }  





SHARE

About Sami Aksoy

    Blogger Comment
    Facebook Comment

0 #type=(blogger):

Yorum Gönder