From c97687b09c49a8a3c0b2ab2a6c5ce914b2f514ba Mon Sep 17 00:00:00 2001 From: Devang Date: Sun, 15 Oct 2017 17:30:36 +0530 Subject: [PATCH] first commit --- .gitignore | 10 ++ app/.gitignore | 1 + app/build.gradle | 38 ++++ app/proguard-rules.pro | 25 +++ .../com/playerdemo/ExampleInstrumentedTest.kt | 24 +++ app/src/main/AndroidManifest.xml | 21 +++ .../main/java/com/playerdemo/MainActivity.kt | 34 ++++ .../java/com/playerdemo/VideoController.kt | 169 ++++++++++++++++++ app/src/main/res/layout/activity_main.xml | 29 +++ app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3358 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 5084 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2386 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 3179 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4648 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 7381 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7008 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 11545 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9442 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 16109 bytes app/src/main/res/values/colors.xml | 6 + app/src/main/res/values/strings.xml | 3 + app/src/main/res/values/styles.xml | 11 ++ .../java/com/playerdemo/ExampleUnitTest.kt | 17 ++ build.gradle | 28 +++ gradle.properties | 17 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53636 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 160 +++++++++++++++++ gradlew.bat | 90 ++++++++++ settings.gradle | 1 + 30 files changed, 690 insertions(+) create mode 100644 .gitignore create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/com/playerdemo/ExampleInstrumentedTest.kt create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/playerdemo/MainActivity.kt create mode 100644 app/src/main/java/com/playerdemo/VideoController.kt create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/styles.xml create mode 100644 app/src/test/java/com/playerdemo/ExampleUnitTest.kt create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f237317 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.externalNativeBuild +.idea/ diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..f74ceec --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,38 @@ +apply plugin: 'com.android.application' + +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' + + +android { + compileSdkVersion 26 + buildToolsVersion "26.0.0" + defaultConfig { + applicationId "com.playerdemo" + minSdkVersion 22 + targetSdkVersion 26 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" + implementation 'com.android.support:appcompat-v7:25.4.0' + testImplementation 'junit:junit:4.12' + implementation 'com.android.support.constraint:constraint-layout:1.0.2' + compile 'de.mrmaffen:vlc-android-sdk:2.0.6' + +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..d546712 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /home/devang/Android/Sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/playerdemo/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/playerdemo/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..3e5c2d6 --- /dev/null +++ b/app/src/androidTest/java/com/playerdemo/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.playerdemo + +import android.support.test.InstrumentationRegistry +import android.support.test.runner.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getTargetContext() + assertEquals("com.playerdemo", appContext.packageName) + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..0995a31 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/playerdemo/MainActivity.kt b/app/src/main/java/com/playerdemo/MainActivity.kt new file mode 100644 index 0000000..09cf22c --- /dev/null +++ b/app/src/main/java/com/playerdemo/MainActivity.kt @@ -0,0 +1,34 @@ +package com.playerdemo + +import android.os.Bundle +import android.support.v7.app.AppCompatActivity +import android.view.View +import android.view.WindowManager +import android.widget.* +import kotlinx.android.synthetic.main.activity_main.* + + +class MainActivity : AppCompatActivity() { + + private var videoView: VideoView? = null + + private var videoController: VideoController?=null + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + this.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + this.window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN) + + setContentView(R.layout.activity_main) + videoView = videoView1 + var etUrl=etURL + etUrl.setText("https://d1pmarobgdhgjx.cloudfront.net/education/ED_pause-and-think-online.mp4") + var btn=btnOk + videoController= VideoController(this) + videoController!!.videoView=videoView + btn.setOnClickListener(View.OnClickListener { + videoController!!.createPlayer(etUrl.text.toString()) + }) + } + +} + diff --git a/app/src/main/java/com/playerdemo/VideoController.kt b/app/src/main/java/com/playerdemo/VideoController.kt new file mode 100644 index 0000000..81f84c9 --- /dev/null +++ b/app/src/main/java/com/playerdemo/VideoController.kt @@ -0,0 +1,169 @@ +package com.playerdemo + +import android.app.Activity +import android.util.Log +import android.widget.MediaController +import android.widget.Toast +import android.widget.VideoView +import org.videolan.libvlc.IVLCVout +import org.videolan.libvlc.LibVLC +import org.videolan.libvlc.MediaPlayer +import java.util.* + + +class VideoController(activity: Activity): IVLCVout.Callback, MediaPlayer.EventListener { + companion object { + // private var logger= Logger.getLogger(VideoController::class.java) + } + + private var mediaPlayer: MediaPlayer?=null + var videoView: VideoView?=null + private var videoWidth: Int = 0 + private var videoHeight: Int = 0 + private var libvlc: LibVLC?=null + private var activity: Activity?=null + init { + this.activity=activity + } + + + /** + * Used to set size for videoView + + * @param width + * * + * @param height + */ + private fun setSize(width: Int, height: Int,screenWidth:Int,screenHeight:Int) { + videoWidth = width + videoHeight = height + var w = screenWidth + var h = screenHeight + + if (videoWidth * videoHeight <= 1) + return + + if ( videoView == null) + return + + val isPortrait =true /*resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT*/ + + if (w > h && isPortrait || w < h && !isPortrait) { + val i = w + w = h + h = i + } + + val videoAR = videoWidth.toFloat() / videoHeight.toFloat() + val screenAR = w.toFloat() / h.toFloat() + + if (screenAR < videoAR) + h = (w / videoAR).toInt() + else + w = (h * videoAR).toInt() + + videoView!!.holder!!.setFixedSize(videoWidth, videoHeight) + val lp = videoView!!.getLayoutParams() + lp.width = w + lp.height = h + videoView!!.setLayoutParams(lp) + videoView!!.invalidate() + } + + /** + * Creates MediaPlayer and plays video + + * @param media + */ + fun createPlayer(media: String) { + releasePlayer() + try { + if (media.length > 0){ + // logger.info(media) + } + + // Create LibVLC + val options = ArrayList() + // options.add("--subsdec-encoding ") + options.add("--aout=opensles") + options.add("--audio-time-stretch") // time stretching + options.add("-vvv") // verbosity + libvlc = LibVLC(activity,options) + + // Creating media player + mediaPlayer = MediaPlayer(libvlc) + mediaPlayer!!.setEventListener(this) + + // Seting up video output + if(videoView!=null){ + videoView!!.setMediaController(MediaController(activity)) + Log.i("url = ",media) + videoView!!.setVideoPath(media) +// videoView!!.setVideoURI(Umedia)) + + videoView!!.setOnPreparedListener(android.media.MediaPlayer.OnPreparedListener { + Log.d("TAG", "OnPrepared called") }) + videoView!!.start() + }else{ + Log.i("error = ","null video view") + } + + } catch (e: Exception) { + Toast.makeText(activity, "Error in creating player!", Toast + .LENGTH_LONG).show() + } + + } + + fun releasePlayer() { + if (libvlc == null) + return + mediaPlayer!!.stop() + var vout: IVLCVout = mediaPlayer!!.vlcVout + vout.removeCallback(this) + vout.detachViews() + videoView = null + libvlc!!.release() + libvlc = null; + videoWidth = 0; + videoHeight = 0; + } + + override fun onEvent(event: MediaPlayer.Event) { + + when (event.type) { + MediaPlayer.Event.EndReached -> { + this.releasePlayer() + } + + MediaPlayer.Event.Playing->Log.i("playing","playing") + MediaPlayer.Event.Paused->Log.i("paused","paused") + MediaPlayer.Event.Stopped->Log.i("stopped","stopped") + else->Log.i("nothing","nothing") + } + } + + override fun onSurfacesCreated(vlcVout: IVLCVout?) { + + } + + override fun onSurfacesDestroyed(vlcVout: IVLCVout?) { + + } + + override fun onNewLayout(vlcVout: IVLCVout?, width: Int, height: Int, visibleWidth: Int, visibleHeight: Int, sarNum: Int, sarDen: Int) { + if (width * height == 0) + return; + + // store video size + videoWidth = width + videoHeight = height + setSize(videoWidth, videoHeight,activity!!.window.decorView.width,activity!!.window.decorView.height) + } + + + override fun onHardwareAccelerationError(vlcVout: IVLCVout?) { + this.releasePlayer() + } + +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..a75cff6 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,29 @@ + + + + +