mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-03-28 18:51:45 +01:00
Adding video playback to the timeline
This commit is contained in:
parent
815f044f77
commit
69fdc4fcd4
@ -95,6 +95,9 @@ dependencies {
|
|||||||
// upload pictures:
|
// upload pictures:
|
||||||
implementation "com.google.accompanist:accompanist-permissions:0.28.0"
|
implementation "com.google.accompanist:accompanist-permissions:0.28.0"
|
||||||
|
|
||||||
|
// view videos
|
||||||
|
implementation 'com.google.android.exoplayer:exoplayer:2.18.2'
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||||
|
@ -8,6 +8,7 @@ import androidx.compose.material.MaterialTheme
|
|||||||
import androidx.compose.material.Surface
|
import androidx.compose.material.Surface
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
|
import com.google.android.exoplayer2.util.Util
|
||||||
import com.vitorpamplona.amethyst.KeyStorage
|
import com.vitorpamplona.amethyst.KeyStorage
|
||||||
import com.vitorpamplona.amethyst.service.NostrAccountDataSource
|
import com.vitorpamplona.amethyst.service.NostrAccountDataSource
|
||||||
import com.vitorpamplona.amethyst.service.NostrGlobalDataSource
|
import com.vitorpamplona.amethyst.service.NostrGlobalDataSource
|
||||||
|
@ -23,6 +23,7 @@ import java.net.URL
|
|||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
val imageExtension = Pattern.compile("(.*/)*.+\\.(png|jpg|gif|bmp|jpeg|webp)$")
|
val imageExtension = Pattern.compile("(.*/)*.+\\.(png|jpg|gif|bmp|jpeg|webp)$")
|
||||||
|
val videoExtension = Pattern.compile("(.*/)*.+\\.(mp4|avi|wmv|mpg|amv|webm)$")
|
||||||
val noProtocolUrlValidator = Pattern.compile("^[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b(?:[-a-zA-Z0-9()@:%_\\+.~#?&//=]*)$")
|
val noProtocolUrlValidator = Pattern.compile("^[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b(?:[-a-zA-Z0-9()@:%_\\+.~#?&//=]*)$")
|
||||||
val tagIndex = Pattern.compile("\\#\\[([0-9]*)\\]")
|
val tagIndex = Pattern.compile("\\#\\[([0-9]*)\\]")
|
||||||
|
|
||||||
@ -59,6 +60,8 @@ fun RichTextViewer(content: String, tags: List<List<String>>?) {
|
|||||||
.clip(shape = RoundedCornerShape(15.dp))
|
.clip(shape = RoundedCornerShape(15.dp))
|
||||||
.border(1.dp, MaterialTheme.colors.onSurface.copy(alpha = 0.12f), RoundedCornerShape(15.dp))
|
.border(1.dp, MaterialTheme.colors.onSurface.copy(alpha = 0.12f), RoundedCornerShape(15.dp))
|
||||||
)
|
)
|
||||||
|
} else if (videoExtension.matcher(removedParamsFromUrl).matches()) {
|
||||||
|
VideoView(word)
|
||||||
} else {
|
} else {
|
||||||
UrlPreview(word, word)
|
UrlPreview(word, word)
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,57 @@
|
|||||||
|
package com.vitorpamplona.amethyst.ui.components
|
||||||
|
|
||||||
|
import android.media.browse.MediaBrowser
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.FrameLayout
|
||||||
|
import androidx.compose.foundation.layout.IntrinsicSize
|
||||||
|
import androidx.compose.foundation.layout.aspectRatio
|
||||||
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.wrapContentHeight
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.DisposableEffect
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.viewinterop.AndroidView
|
||||||
|
import com.google.android.exoplayer2.C
|
||||||
|
import com.google.android.exoplayer2.ExoPlayer
|
||||||
|
import com.google.android.exoplayer2.MediaItem
|
||||||
|
import com.google.android.exoplayer2.Player
|
||||||
|
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout
|
||||||
|
import com.google.android.exoplayer2.ui.StyledPlayerView
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun VideoView(videoUri: String) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
val exoPlayer = ExoPlayer.Builder(LocalContext.current).build().apply {
|
||||||
|
playWhenReady = true
|
||||||
|
repeatMode = Player.REPEAT_MODE_ALL
|
||||||
|
videoScalingMode = C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING
|
||||||
|
setMediaItem(MediaItem.fromUri(videoUri))
|
||||||
|
prepare()
|
||||||
|
}
|
||||||
|
|
||||||
|
DisposableEffect(exoPlayer) {
|
||||||
|
onDispose {
|
||||||
|
exoPlayer.release()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println("CCC"+exoPlayer.videoFormat?.width)
|
||||||
|
AndroidView(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth(),
|
||||||
|
factory = {
|
||||||
|
StyledPlayerView(context).apply {
|
||||||
|
player = exoPlayer
|
||||||
|
layoutParams = FrameLayout.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
|
)
|
||||||
|
resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIXED_WIDTH
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user