How can i run javascript in Kodular?

//There are many topics in kodular community but none seems to be useful to me.

how can i run javascript in kodular using a extension or something else,
suggestions:- Kodular needs the ability to run Java Scripits

use webviewer has block ‘Evaluate JS’ for running js.


you will have to search in community first

but i searched and red others topic

so what problem you have with this block

not working

show script what you are trying

here is it:-
package com.android.audiorecordtest

import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.media.MediaPlayer
import android.media.MediaRecorder
import android.os.Bundle
import android.support.v4.app.ActivityCompat
import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.View.OnClickListener
import android.view.ViewGroup
import android.widget.Button
import android.widget.LinearLayout
import java.io.IOException

private const val LOG_TAG = “AudioRecordTest”
private const val REQUEST_RECORD_AUDIO_PERMISSION = 200

class AudioRecordTest : AppCompatActivity() {

private var fileName: String = ""

private var recordButton: RecordButton? = null
private var recorder: MediaRecorder? = null

private var playButton: PlayButton? = null
private var player: MediaPlayer? = null

// Requesting permission to RECORD_AUDIO
private var permissionToRecordAccepted = false
private var permissions: Array<String> = arrayOf(Manifest.permission.RECORD_AUDIO)

override fun onRequestPermissionsResult(
        requestCode: Int,
        permissions: Array<String>,
        grantResults: IntArray
) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults)
    permissionToRecordAccepted = if (requestCode == REQUEST_RECORD_AUDIO_PERMISSION) {
        grantResults[0] == PackageManager.PERMISSION_GRANTED
    } else {
        false
    }
    if (!permissionToRecordAccepted) finish()
}

private fun onRecord(start: Boolean) = if (start) {
    startRecording()
} else {
    stopRecording()
}

private fun onPlay(start: Boolean) = if (start) {
    startPlaying()
} else {
    stopPlaying()
}

private fun startPlaying() {
    player = MediaPlayer().apply {
        try {
            setDataSource(fileName)
            prepare()
            start()
        } catch (e: IOException) {
            Log.e(LOG_TAG, "prepare() failed")
        }
    }
}

private fun stopPlaying() {
    player?.release()
    player = null
}

private fun startRecording() {
    recorder = MediaRecorder().apply {
        setAudioSource(MediaRecorder.AudioSource.MIC)
        setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP)
        setOutputFile(fileName)
        setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB)

        try {
            prepare()
        } catch (e: IOException) {
            Log.e(LOG_TAG, "prepare() failed")
        }

        start()
    }
}

private fun stopRecording() {
    recorder?.apply {
        stop()
        release()
    }
    recorder = null
}

internal inner class RecordButton(ctx: Context) : Button(ctx) {

    var mStartRecording = true

    var clicker: OnClickListener = OnClickListener {
        onRecord(mStartRecording)
        text = when (mStartRecording) {
            true -> "Stop recording"
            false -> "Start recording"
        }
        mStartRecording = !mStartRecording
    }

    init {
        text = "Start recording"
        setOnClickListener(clicker)
    }
}

internal inner class PlayButton(ctx: Context) : Button(ctx) {
    var mStartPlaying = true
    var clicker: OnClickListener = OnClickListener {
        onPlay(mStartPlaying)
        text = when (mStartPlaying) {
            true -> "Stop playing"
            false -> "Start playing"
        }
        mStartPlaying = !mStartPlaying
    }

    init {
        text = "Start playing"
        setOnClickListener(clicker)
    }
}

override fun onCreate(icicle: Bundle?) {
    super.onCreate(icicle)

    // Record to the external cache directory for visibility
    fileName = "${externalCacheDir.absolutePath}/audiorecordtest.3gp"

    ActivityCompat.requestPermissions(this, permissions, REQUEST_RECORD_AUDIO_PERMISSION)

    recordButton = RecordButton(this)
    playButton = PlayButton(this)
    val ll = LinearLayout(this).apply {
        addView(recordButton,
                LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        0f))
        addView(playButton,
                LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT,
                        0f))
    }
    setContentView(ll)
}

override fun onStop() {
    super.onStop()
    recorder?.release()
    recorder = null
    player?.release()
    player = null
}

}

whats wrong with it?

What you are trying to run is Java not Javascript.

6 Likes

There is all wrong you just copied some code from somewhere and paste it and also didn’t know what code was is java or JavaScript.

2 Likes

hoo, sorry how did you get to know and which javascript i can use for screen recording programme?
i thought java and javascript are same

Google is your best friend.

2 Likes

hey man its difficult to find,

No they are not same.
JavaScript is for web while Java is for almost every environment which has JRE

You want to make screen recording app for that app need to over other app which is not possible for kodular yet

1 Like

It’s neither Java nor JavaScript. It’s Kotlin, man! :crazy_face::joy:

7 Likes

A post was split to a new topic: I want to run this javascript when webview page load