有没有办法拦截或只是读取Android设备中的音频输出?
我需要从myActivity内部读取PCM中的整个音频输出,包括背景中的媒体播放器应用,来自呼叫的语音,myACtivity内的MediaPlayer等等,以及扬声器播放的所有内容.实际上,如果可以单独阅读它们,也会很棒.
我试着用AudioRecord,给它作为参数的AudioSource每不断发现MediaRecorder.AudioSource没有运气,我应该尝试不同的audioSources?
它是一个如此低级别的任务,必须在本机层内处理?
只是想验证Application.onCreate()保证在之前被调用BroadcastReceiver.onReceive()?假设您正在等待BOOT广播或短信广播,您能否确定Application.onCreate()在您到达之前已经呼叫过一次BroadcastReceiver.onReceive()?谢谢
编译器显示错误Kotlin:result必须初始化变量.
这是代码.
fun main(args: Array<String>) {
print("Enter two numbers: ")
// nextDouble() reads the next double from the keyboard
var first= readLine()!!.toDouble()
var second = readLine()!!.toInt()
print("Enter an choice(1-4)): ")
val operator = readLine()!!.toInt()
var result: Double
when (operator) {
1 -> result = first + second
2 -> result = first - second
3 -> result = first * second
4 -> result = first / second
else -> {
println("Error.")
}
}
println("The result is :- …Run Code Online (Sandbox Code Playgroud) 我正在使用 Android 数据绑定库来绑定具有 <include>
布局文件
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="model"
type="com.example.MyViewModel" />
</data>
...
<include
layout="@layout/someOtherLayout"
android:id="@+id/includedLayout" />
...
</layout>
Run Code Online (Sandbox Code Playgroud)
在为 xml 生成的数据绑定类中,我看到了这个属性:
@Nullable
public final com.example.databinding.SomeOtherLayoutBinding includedLayout;
Run Code Online (Sandbox Code Playgroud)
为什么将其注释为@Nullable?该<include>是在布局,在我看来,这显然是不为空。我错过了什么?
它迫使我!!在访问包含的布局的字段时在 Kotlin 代码中使用非空断言运算符,我想知道它是否安全或者是否有我在这里没有考虑的东西
val binder = DataBindingUtil.bind(view)
val someView = binder.includedLayout!!.someView
Run Code Online (Sandbox Code Playgroud) 在Java中,可以为Activity定义一种入门静态方法。在Android Studio中,甚至还有一个“入门”模板:它看起来像这样:
public class MyActivity extends AppCompatActivity {
private static final String EXTRA_FOO = "foo";
public static void start(Context caller, String bar){
Intent intent = new Intent(caller, MyActivity.class);
intent.putExtra(EXTRA_FOO, bar);
caller.startActivity(intent);
}
}
Run Code Online (Sandbox Code Playgroud)
我用Kotlin围绕着这个相同的概念,我想到的最接近的东西是这样的:
class MyActivity : AppCompatActivity() {
companion object {
private val EXTRA_FOO = "foo"
fun start(caller: Context, bar: String){
val intent = Intent(caller, MyActivity::class.java)
intent.putExtra(EXTRA_FOO, bar)
caller.startActivity(intent)
}
}
}
Run Code Online (Sandbox Code Playgroud)
有没有更简洁,优雅的方法可以做到这一点?我不敢相信这是要走的路,它看起来比Java中的丑陋。另外,没有Kotlin的“入门”模板。
例如,我有一个改造界面,例如:
interface SampleService {
fun getSomething(@body someBody: SomeBody)
}
Run Code Online (Sandbox Code Playgroud)
现在我有一个使用这个接口的类,例如:
class UserRequester(val service: SampleService) {
fun doGetSomething(someValue: String) {
val response = service.getSomething(SomeBody(someValue))
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
我想测试这个类,但不知道如何模拟它。
我正在尝试以下操作:
val mockSampleService = mock()
val userRequester = UserRequester(mockSampleService)
val requestBody = SomeBody(someString))
when(mockSampleService.getSomething(requestBody)).return(myExpectedValue)
....
Run Code Online (Sandbox Code Playgroud)
我的问题是,由于我在函数内部创建了请求对象,因此我无法使模拟 when().thenReturn() 工作,因为我在技术上传递了两个不同的对象。
我应该如何测试这个?提前致谢。
我有两个C++类,Container和Item,看起来像:
class Item{
public:
Item(std::string* name,int id);
std::string* getName();
private:
std::string* name;
int id;
};
class Container {
public:
Container();
Item* getItem(int id);
private:
std::vector<Item*> items;
};
Run Code Online (Sandbox Code Playgroud)
我想在Python中创建和使用Container,所以我编写了一个C接口来编译共享库:
extern "C" {
Container* Container_init(){return new Container();}
Item* Container_getItem(Container* container,int id){return container->getItem(id);}
std::string* Item_getName(Item* item){return item->getName();}
}
Run Code Online (Sandbox Code Playgroud)
和一个Python包装器:
from ctypes import *
lib = cdll.LoadLibrary(myLibPath)
class Item(object):
def getName(self):
return lib.Item_getName(self.obj)
class Container(object):
def __init__(self):
self.obj = lib.Container_init()
def getItem(self,id):
return lib.Container_getItem(self.obj,id)
lib.Container_getItem.restype = Item
lib.Container_getItem.argtypes = [c_void_p,c_int]
c = Container()
print …Run Code Online (Sandbox Code Playgroud) 我正在无缝ConcatenatingMediaSource地玩很多MediaSource游戏,这很有趣,但是当玩家开始播放下一个MediaSource.
ExoPlayer.EventLister.onTracksChanged(TrackGroupArray, TrackSelected)在MediaSource更改时被调用(我可以在那时听到新曲目),所以它似乎是正确的地方,但我如何检索MediaSource正在播放的索引?
MediaSource[] allSources = // ...
ConcatenatingMediaSource source = new ConcatenatingMediaSource(allSources);
ExoPlayer player = // ..
player.prepare(source);
// ...
@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
// Can I retrieve the index of the MediaSource currently being played here?
// If not, where!?
}
Run Code Online (Sandbox Code Playgroud) 这是我的代码的一部分:
Color[] color = new Color[3];
color [0] = Color.red;
color[1] = Color.blue;
color[2] = Color.yellow;
stage.getBatch().setColor(color[rand.nextInt()]);
Run Code Online (Sandbox Code Playgroud)
但是“ color [rand.nextInt()]);” 带红色下划线。我真的不知道为什么。括号中必须有四个数字或“ Color.BLUE”,但我想随机着色精灵。因此,我创建了一个具有三种颜色的数组。我认为只要给他们数字并使用rand.nextInt就可以了。怎么了
如何从特定的mipmap图像中读取字节?例如,我正在尝试从ic_launcher.png中读取位于mipmap-xxhdpi的字节
这是我正在尝试做的事情:
InputStream ins = getResources().
openRawResource(getResources().
getIdentifier("ic_launcher.png",
"mipmap-xxhdpi", getPackageName()));
Run Code Online (Sandbox Code Playgroud)
但我得到一个例外,说没有找到资源.做正确的方法是什么?我想特别读取mipmap-xxhdpi中的文件
我如何在改造网络调用中使用这些查询并将其显示在类别明智的结果中
https://api.themoviedb.org/3/genre/{genre_id}/movies
Run Code Online (Sandbox Code Playgroud)