Unverified Commit 7313b7bc authored by Filipe de Lima Brito's avatar Filipe de Lima Brito Committed by GitHub

Merge pull request #631 from filipedelimabrito/feature/support-viewing-video

[Feature] Support viewing video
parents f4521db1 fa48430d
......@@ -12,10 +12,11 @@ android {
minSdkVersion 21
targetSdkVersion versions.targetSdk
versionCode 1
versionName "1.0"
versionName "2.0.0-beta1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
......@@ -32,6 +33,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':core')
implementation project(':player')
implementation libraries.kotlin
implementation libraries.coroutines
......
......@@ -15,18 +15,19 @@
android:layout_below="@id/text_headline"
android:layout_marginTop="32dp"
android:gravity="center_vertical"
android:text="@string/default_protocol"/>
android:text="@string/default_protocol" />
<EditText
android:id="@+id/text_server_url"
style="@style/AuthenticationEditText"
android:layout_below="@id/text_headline"
android:layout_toEndOf="@id/server_protocol_label"
android:layout_marginTop="32dp"
android:layout_marginStart="0dp"
android:paddingStart="0dp"
android:layout_marginTop="32dp"
android:layout_toEndOf="@id/server_protocol_label"
android:hint="@string/default_server"
android:imeOptions="actionDone"
android:inputType="textUri"
android:hint="@string/default_server" />
android:paddingStart="0dp" />
<Button
android:id="@+id/button_connect"
......
......@@ -6,6 +6,7 @@ buildscript {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
......@@ -20,10 +21,8 @@ allprojects {
repositories {
google()
jcenter()
maven {
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
maven { url 'https://jitpack.io' }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://jitpack.io" }
}
apply from: rootProject.file('dependencies.gradle')
......
......@@ -6,7 +6,7 @@ ext {
compileSdk : 27,
targetSdk : 27,
buildTools : '27.0.0',
kotlin : '1.2.0',
kotlin : '1.2.10',
coroutine : '0.20',
dokka : '0.9.15',
......@@ -14,6 +14,7 @@ ext {
support : '27.0.2',
constraintLayout : '1.0.2',
dagger : '2.13',
exoPlayer : '2.6.0',
room : '1.0.0',
rxjava : '2.1.4',
rxandroid : '2.0.1',
......@@ -48,6 +49,7 @@ ext {
daggerSupport : "com.google.dagger:dagger-android-support:${versions.dagger}",
daggerProcessor : "com.google.dagger:dagger-compiler:${versions.dagger}",
daggerAndroidApt : "com.google.dagger:dagger-android-processor:${versions.dagger}",
exoPlayer : "com.google.android.exoplayer:exoplayer:${versions.exoPlayer}",
room : "android.arch.persistence.room:runtime:${versions.room}",
roomProcessor : "android.arch.persistence.room:compiler:${versions.room}",
......
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion versions.compileSdk
defaultConfig {
minSdkVersion 21
targetSdkVersion versions.targetSdk
versionCode 1
versionName "1.0.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'])
implementation libraries.kotlin
implementation libraries.appCompat
implementation libraries.exoPlayer
testImplementation libraries.junit
}
\ No newline at end of file
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# 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
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="chat.rocket.android.player">
<application>
<activity
android:name=".PlayerActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize|uiMode"
android:theme="@style/PlayerTheme" />
</application>
</manifest>
\ No newline at end of file
package chat.rocket.android.player
import android.net.Uri
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import com.google.android.exoplayer2.DefaultLoadControl
import com.google.android.exoplayer2.DefaultRenderersFactory
import com.google.android.exoplayer2.ExoPlayerFactory
import com.google.android.exoplayer2.SimpleExoPlayer
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory
import com.google.android.exoplayer2.source.ExtractorMediaSource
import com.google.android.exoplayer2.source.MediaSource
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory
import com.google.android.exoplayer2.util.Util
import kotlinx.android.synthetic.main.activity_player.*
class PlayerActivity : AppCompatActivity() {
private lateinit var player: SimpleExoPlayer
private var isPlayerInitialized = false
private var playWhenReady = true
private var currentWindow = 0
private var playbackPosition = 0L
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_player)
}
override fun onStart() {
super.onStart()
if (Util.SDK_INT > 23) {
initializePlayer()
}
}
override fun onResume() {
super.onResume()
hideSystemUi()
if (Util.SDK_INT <= 23 || !isPlayerInitialized) {
initializePlayer()
}
}
override fun onPause() {
super.onPause()
if (Util.SDK_INT <= 23) {
releasePlayer()
}
}
override fun onStop() {
super.onStop()
if (Util.SDK_INT > 23) {
releasePlayer()
}
}
private fun initializePlayer() {
if (!isPlayerInitialized) {
player = ExoPlayerFactory.newSimpleInstance(DefaultRenderersFactory(this), DefaultTrackSelector(), DefaultLoadControl())
player_view.player = player
player.playWhenReady = playWhenReady
player.seekTo(currentWindow, playbackPosition)
isPlayerInitialized = true
}
val uri = Uri.parse("http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4")
val mediaSource = buildMediaSource(uri)
player.prepare(mediaSource, true, false)
}
private fun releasePlayer() {
if (isPlayerInitialized) {
playbackPosition = player.currentPosition
currentWindow = player.currentWindowIndex
playWhenReady = player.playWhenReady
player.release()
isPlayerInitialized = false
}
}
private fun buildMediaSource(uri: Uri): MediaSource = ExtractorMediaSource(uri, DefaultHttpDataSourceFactory("rocket-chat-android-player"), DefaultExtractorsFactory(), null, null)
private fun hideSystemUi() {
// Read the docs for detailed explanation: https://developer.android.com/training/basics/firstapp/starting-activity.html and https://developer.android.com/design/patterns/fullscreen.html
player_view.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="@+id/player_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
\ No newline at end of file
<resources>
<string name="app_name">Rocket Chat Android Player library</string>
</resources>
\ No newline at end of file
<resources>
<style name="PlayerTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@null</item>
</style>
</resources>
\ No newline at end of file
include ':app', 'common', 'core'
include ':app', 'common', 'core', ':player'
project(':common').projectDir = new File(settingsDir, '../Rocket.Chat.Kotlin.Sdk/common')
project(':core').projectDir = new File(settingsDir, '../Rocket.Chat.Kotlin.Sdk/core')
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment