Kotlin Kursu etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
Kotlin Kursu etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
9 Mayıs 2024 Perşembe
2 Nisan 2024 Salı
2 Mart 2024 Cumartesi
Kotlin Video Player
İ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()
- }
- }
27 Şubat 2024 Salı
Kotlin Fotoğrafları Arkaplan Yapma Programı Kodları
```kotlin
import android.os.Bundle
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val imageView: ImageView = findViewById(R.id.imageView)
imageView.setImageResource(R.drawable.background_image)
}
}
```
Output:
The code provided sets a background image from the assets folder in an ImageView in an Android app using Kotlin.
Kotlin Audio Recorder
import android.Manifest
import android.content.pm.PackageManager
import android.media.MediaRecorder
import android.os.Bundle
import android.os.Environment
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import java.io.IOException
class MainActivity : AppCompatActivity() {
private lateinit var mediaRecorder: MediaRecorder
private var outputFile: String = ""
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val recordButton: Button = findViewById(R.id.record_button)
if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.RECORD_AUDIO), 1)
}
outputFile = Environment.getExternalStorageDirectory().absolutePath + "/recording.3gp"
mediaRecorder = MediaRecorder()
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC)
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP)
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB)
mediaRecorder.setOutputFile(outputFile)
recordButton.setOnClickListener {
try {
mediaRecorder.prepare()
mediaRecorder.start()
Toast.makeText(this, "Recording started", Toast.LENGTH_SHORT).show()
} catch (e: IOException) {
e.printStackTrace()
}
}
}
override fun onStop() {
super.onStop()
mediaRecorder.stop()
mediaRecorder.release()
Toast.makeText(this, "Recording stopped", Toast.LENGTH_SHORT).show()
}
}
23 Şubat 2024 Cuma
Kotlin Audio Recorder Örneği
import android.Manifest
import android.content.pm.PackageManager
import android.media.MediaRecorder
import android.os.Bundle
import android.os.Environment
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import java.io.IOException
class AudioRecorderActivity : AppCompatActivity() {
private lateinit var mediaRecorder: MediaRecorder
private var isRecording = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_audio_recorder)
val recordButton = findViewById<Button>(R.id.record_button)
recordButton.setOnClickListener {
if (isRecording) {
stopRecording()
} else {
if (checkPermissions()) {
startRecording()
}
}
}
}
private fun startRecording() {
mediaRecorder = MediaRecorder()
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC)
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP)
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB)
val filePath = Environment.getExternalStorageDirectory().absolutePath + "/recording.3gp"
mediaRecorder.setOutputFile(filePath)
try {
mediaRecorder.prepare()
mediaRecorder.start()
isRecording = true
Toast.makeText(this, "Recording started", Toast.LENGTH_SHORT).show()
} catch (e: IOException) {
e.printStackTrace()
}
}
private fun stopRecording() {
mediaRecorder.stop()
mediaRecorder.release()
isRecording = false
Toast.makeText(this, "Recording stopped", Toast.LENGTH_SHORT).show()
}
private fun checkPermissions(): Boolean {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.RECORD_AUDIO), 1)
return false
}
return true
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == 1 && grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
startRecording()
} else {
Toast.makeText(this, "Permission denied", Toast.LENGTH_SHORT).show()
}
}
}
Kaydol:
Kayıtlar (Atom)