Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
devangeinfochips committed Oct 15, 2017
1 parent e159298 commit c97687b
Show file tree
Hide file tree
Showing 30 changed files with 690 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
.idea/
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
38 changes: 38 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -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'

}
25 changes: 25 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions app/src/androidTest/java/com/playerdemo/ExampleInstrumentedTest.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}
21 changes: 21 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.playerdemo">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
34 changes: 34 additions & 0 deletions app/src/main/java/com/playerdemo/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -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())
})
}

}

169 changes: 169 additions & 0 deletions app/src/main/java/com/playerdemo/VideoController.kt
Original file line number Diff line number Diff line change
@@ -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<String>()
// options.add("--subsdec-encoding <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()
}

}
29 changes: 29 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">

<EditText
android:id="@+id/etURL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />

<Button
android:id="@+id/btnOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="OK" />

<VideoView
android:id="@+id/videoView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />



</LinearLayout>
Binary file added app/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">PlayerDemo</string>
</resources>
11 changes: 11 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>
Loading

0 comments on commit c97687b

Please sign in to comment.