我有一个默认的 .mp4 文件,我想使用 ExoPlayer(在 Android 上)查看该文件。我用这个小视频:
http://techslides.com/demos/sample-videos/small.mp4
在应用程序中,我得到一个 base64 字符串,即视频。当我将上面的视频粘贴到该网站时:
https://base64.guru/converter/encode/video
它显示的 Base64 值与应用程序中接收到的值相同,但会引发以下错误。
player.playFromBytes(currentVideoBase64?.toByteArray()!!)
override fun playFromBytes(byteArray: ByteArray) {
val mediaSource = createMediaSourceFromByteArray(byteArray)
exoPlayer.prepare(mediaSource)
exoPlayer.playWhenReady = true
}
private fun createMediaSourceFromByteArray(data: ByteArray): MediaSource {
val byteArrayDataSource = ByteArrayDataSource(data)
val factory = DataSource.Factory { byteArrayDataSource }
val mediaSource = ProgressiveMediaSource.Factory(factory, DefaultExtractorsFactory())
.createMediaSource(Uri.EMPTY)
return Objects.requireNonNull(mediaSource, "MediaSource cannot be null")
}
Run Code Online (Sandbox Code Playgroud)
错误信息:
2019-09-18 18:09:59.970 18009-18743/ E/ExoPlayerImplInternal: Source error.
com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors (MatroskaExtractor, FragmentedMp4Extractor, Mp4Extractor, Mp3Extractor, AdtsExtractor, Ac3Extractor, TsExtractor, FlvExtractor, …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中实现了黑暗/夜间模式切换,我从Google I/O App复制了该实现。
我创建了一个可以包含在 ViewModel 中的ThemedActivityDelegate 。实际更改为亮或暗是使用扩展函数完成的:updateForTheme。
但我看到SettingsActivity白色短暂闪烁,然后变成黑色。虽然我updateForTheme之前把方法放了setContentView。
主要活动:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
viewModel = ViewModelProvider(this, viewModelFactory).get(MainViewModel::class.java)
updateForTheme(viewModel.currentTheme)
lifecycleScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
launch {
viewModel.theme.collect { theme ->
updateForTheme(theme)
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
扩展.kt:
fun AppCompatActivity.updateForTheme(theme: Theme) = when (theme) {
Theme.DARK -> delegate.localNightMode = AppCompatDelegate.MODE_NIGHT_YES
Theme.LIGHT -> delegate.localNightMode = AppCompatDelegate.MODE_NIGHT_NO
Theme.SYSTEM -> delegate.localNightMode = AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
Theme.BATTERY_SAVER -> delegate.localNightMode = AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY …Run Code Online (Sandbox Code Playgroud) 没有对annotationProcessor的引用build.gradle,我只使用kotlin-kapt:
apply plugin: 'kotlin-kapt'
Run Code Online (Sandbox Code Playgroud)
我的事件日志显示0警告/错误:
10-05-18
13:24 Executing tasks: [clean, :storage:generateDebugSources, :pagination:generateDebugSources, :validation:generateDebugSources, :validation-ui:generateDebugSources, :misnap:generateDebugSources, :openam:generateDebugSources, :domain:generateDebugSources, :core:generateDebugSources, :crypto:generateDebugSources, :interactors:generateDebugSources, :analytics:generateDebugSources, :app:generateDevNlDebugSources, :midlayer:generateDebugSources, :coverflow:generateDebugSources, :debug-ui:generateDebugSources, :encap:generateDebugSources]
13:24 Gradle build finished in 7s 550ms
13:25 Executing tasks: [:app:assembleDevNlDebug]
13:26 Gradle build finished in 1m 2s 902ms
Run Code Online (Sandbox Code Playgroud)
这是输出:
org.gradle.api.GradleException: Compilation error. See log for more details
at org.jetbrains.kotlin.gradle.tasks.TasksUtilsKt.throwGradleExceptionIfError(tasksUtils.kt:8)
at org.jetbrains.kotlin.gradle.internal.KaptTask.compile(KaptTask.kt:124)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:46)
at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39) …Run Code Online (Sandbox Code Playgroud) 安装Android Studio 3.3后,"选择部署目标"在没有连接的设备和不存在的模拟器之间切换.
每次尝试在模拟器或真实设备上安装应用程序时,都会显示以下错误消息:
02/01 18:05:26: Launching app
$ adb push /Users/jimclermonts/Documents/Android-Code/sources/app/build/outputs/apk/acceptance/debug/app-acceptance-debug.apk /data/local/tmp/nl.mycompanyname.acc
Device emulator-5556disconnected, monitoring stopped.
Error while Installing APK
Run Code Online (Sandbox Code Playgroud)
这是一个显示奇怪切换的视频:
我尝试以编程方式杀死它但它不断启动自己:
Mac-van-Jim:~ jimclermonts$ adb devices
List of devices attached
emulator-5556 offline
Mac-van-Jim:~ jimclermonts$ adb devices
List of devices attached
Mac-van-Jim:~ jimclermonts$ adb devices
List of devices attached
Mac-van-Jim:~ jimclermonts$ adb devices
List of devices attached
emulator-5556 offline
Mac-van-Jim:~ jimclermonts$ adb devices
List of devices attached
Mac-van-Jim:~ jimclermonts$ adb -s emulator-5556 emu kill
Mac-van-Jim:~ jimclermonts$ adb -s emulator-5556 emu …Run Code Online (Sandbox Code Playgroud) 当我在扩展FirebaseMessagingService的服务中收到Push消息并在此类中启动Activity时,将执行以下生命周期事件/方法:
我开发了下面的解决方案,我在其中添加一个布尔值,以确定屏幕是否打开/关闭.但这很麻烦,当屏幕在锁定模式下打开时,它不起作用.
因为当屏幕未关闭且显示MainActivity,并且接收到推送消息时,该行为是默认的生命周期行为,因此是正确的.打开屏幕并显示MainActivity时,这是相同的流程:
这是正确的,也是可以预期的.
class VideoRingingActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
if (ViewUtils.isScreenActive(activity)) {
screenIsNotLocked = true
}
ViewUtils.disableLockScreen(this)
binding = DataBindingUtil.setContentView(this, R.layout.activity_video_ringing)
}
override fun onStart() {
super.onStart()
if (screenIsNotLocked) {
}
}
override fun onResume() {
super.onResume()
if (screenIsNotLocked) {
}
}
override fun onPause() {
super.onPause()
if (screenIsNotLocked) {
}
}
override fun onStop() {
super.onStop()
if …Run Code Online (Sandbox Code Playgroud) 我编写了一种方法来禁用Android锁定屏幕,并使屏幕从待机状态(用于拨号)打开。此方法可正常工作30秒,但随后会触发待机屏幕,该屏幕短暂闪烁。这会触发onPause,onStop,onResume。这不应该发生。哪个标志不正确?实施必须从最新的Android版本开始,直到API 19。
此错误仅在<8.0以下的Android设备上发生。
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
disableLockScreen(this)
setContentView(R.layout.activity_main)
Log.i("AppLifecycleTest", "onCreate")
}
override fun onResume() {
super.onResume()
Log.i("AppLifecycleTest", "onResume")
}
override fun onPause() {
super.onPause()
Log.i("AppLifecycleTest", "onPause")
}
override fun onStop() {
super.onStop()
Log.i("AppLifecycleTest", "onStop")
}
override fun onDestroy() {
super.onDestroy()
Log.i("AppLifecycleTest", "onDestroy")
}
@Suppress("DEPRECATION")
private fun disableLockScreen(activity: Activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
activity.setShowWhenLocked(true)
activity.setTurnScreenOn(true)
}
val lock =
(activity.getSystemService(Activity.KEYGUARD_SERVICE) as KeyguardManager).newKeyguardLock(Context.KEYGUARD_SERVICE)
val powerManager = activity.getSystemService(Context.POWER_SERVICE) as PowerManager
val wake = powerManager.newWakeLock(
PowerManager.FULL_WAKE_LOCK or
PowerManager.ACQUIRE_CAUSES_WAKEUP or …Run Code Online (Sandbox Code Playgroud) 我正在初始化一个带有图标(国家/地区标志)和电话号码的下拉菜单。前缀(字符串)。当我在 XML 中设置 drawable 时,它可以工作:
app:drawableStartCompat="@drawable/flag_afn"
Run Code Online (Sandbox Code Playgroud)
但是当我以编程方式找到视图时,使用
setCompoundDrawablesWithIntrinsicBounds
Run Code Online (Sandbox Code Playgroud)
它不起作用。
主活动.kt
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val viewGroup =
(findViewById<View>(android.R.id.content) as ViewGroup).getChildAt(0) as ViewGroup
initializeSpinner(viewGroup)
}
private fun initializeSpinner(parent: ViewGroup) {
ArrayAdapter.createFromResource(
this,
R.array.phone_country_codes,
R.layout.spinner_dropdown_item
).also { adapter ->
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item)
// Apply the adapter to the spinner
phonePrefix.adapter = adapter
for (cnt in 0 until adapter.count) {
val drawable = ContextCompat.getDrawable(this, R.drawable.flag_bmd)
val view = adapter.getView(cnt, null, …Run Code Online (Sandbox Code Playgroud) from abc import abstractmethod, ABCMeta
class AbstractBase(object):
__metaclass__ = ABCMeta
@abstractmethod
def must_implement_this_method(self):
raise NotImplementedError()
class ConcreteClass(AbstractBase):
def extra_function(self):
print('hello')
# def must_implement_this_method(self):
# print("Concrete implementation")
d = ConcreteClass() # no error
d.extra_function()
Run Code Online (Sandbox Code Playgroud)
我在使用Python 3.4.我想定义一个抽象基类,它定义了需要由它的子类实现的某些函数.但是当子类没有实现函数时,Python不会引发NotImplementedError ...
它必须是这样的:
目前它看起来像这样:
圆角矩形并不重要.但是未经检查的状态必须是黑色的.这是我的代码:
<CheckBox
android:id="@+id/checkbox"
android:buttonTint="@color/orange"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的主题:
"Theme.AppCompat.Light.NoActionBar"
Run Code Online (Sandbox Code Playgroud)
我也试过这个:
<style name="checkbox_style" parent="Bijenkorf">
<item name="material_grey_600">@color/black</item>
</style>
Run Code Online (Sandbox Code Playgroud)
因为未选中的默认值为#757575.我在主题中看了这个,它是"material_grey_600".但这不编译.有任何想法吗?
我正在尝试在 Android 上运行 HtmlUnit。我认为这个答案曾经适用于较旧的库,但不再适用。与此问题相关的其他线程与 Android 上的 Kotlin 无关或已过时。
考虑下面的代码:
https://github.com/JimClermonts/HtmlUnit-for-Android
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
doAsync {
val webClient = WebClient()
var page: HtmlPage = webClient.getPage<HtmlPage>("http://www.google.com")
val searchBox = page.getElementByName<HtmlInput>("q")
searchBox.valueAttribute = "htmlunit"
val googleSearchSubmitButton: HtmlSubmitInput = page.getElementByName("btnG") // sometimes it's "btnK"
page = googleSearchSubmitButton.click()
val resultStatsDiv: HtmlDivision = page.getFirstByXPath("//div[@id='resultStats']")
System.out.println(resultStatsDiv.asText()) // About 309,000 results
webClient.close()
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的项目依赖项:
dependencies {
implementation group: 'commons-io', name: 'commons-io', version: '2.6'
// implementation group: 'commons-logging', name: 'commons-logging', version: '1.2' …Run Code Online (Sandbox Code Playgroud) android ×9
kotlin ×3
annotations ×1
checkbox ×1
exoplayer ×1
exoplayer2.x ×1
gradle ×1
htmlunit ×1
kapt ×1
lockscreen ×1
python ×1
python-3.4 ×1
python-3.x ×1
xml ×1