在我的应用程序中,我正在尝试上传用户从图库中选择的一些视频.问题是通常android视频文件太大而无法上传,因此我们希望首先通过较低的比特率/分辨率来压缩它们.
我刚刚听说过使用API 16引入的新MediaCodec api(我以前试图用ffmpeg这样做).
我现在正在做的是:首先使用视频解码器解码输入视频,并使用从输入文件中读取的格式对其进行配置.接下来,我创建了一个带有一些预定义参数的标准视频编码器,并用它来编码解码器输出缓冲区.然后我将编码器输出缓冲区保存到文件中.
一切看起来都很好 - 从每个输入和输出缓冲区写入和读取相同数量的数据包,但最终文件看起来不像视频文件,任何视频播放器都无法打开.
看起来解码没问题,因为我通过在Surface上显示它来测试它.我首先配置解码器以使用Surface,当我们调用releaseOutputBuffer时,我们使用render标志,我们可以在屏幕上看到视频.
这是我正在使用的代码:
//init decoder
MediaCodec decoder = MediaCodec.createDecoderByType(mime);
decoder.configure(format, null , null , 0);
decoder.start();
ByteBuffer[] codecInputBuffers = decoder.getInputBuffers();
ByteBuffer[] codecOutputBuffers = decoder.getOutputBuffers();
//init encoder
MediaCodec encoder = MediaCodec.createEncoderByType(mime);
int width = format.getInteger(MediaFormat.KEY_WIDTH);
int height = format.getInteger(MediaFormat.KEY_HEIGHT);
MediaFormat mediaFormat = MediaFormat.createVideoFormat(mime, width, height);
mediaFormat.setInteger(MediaFormat.KEY_BIT_RATE, 400000);
mediaFormat.setInteger(MediaFormat.KEY_FRAME_RATE, 25);
mediaFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatYUV420SemiPlanar);
mediaFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 5);
encoder.configure(mediaFormat, null , null , MediaCodec.CONFIGURE_FLAG_ENCODE);
encoder.start();
ByteBuffer[] encoderInputBuffers = encoder.getInputBuffers();
ByteBuffer[] encoderOutputBuffers = encoder.getOutputBuffers();
extractor.selectTrack(0);
boolean sawInputEOS = false; …Run Code Online (Sandbox Code Playgroud) 我刚刚开始使用ActionBarSherlock构建一些简单的应用程序,在我的第一个屏幕中我有简单的列表,我添加了新的菜单项,用于向列表添加新项目:
MenuItem newItem = menu.add("New");
newItem.setIcon(R.drawable.ic_compose_inverse)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
Run Code Online (Sandbox Code Playgroud)
现在当用户选择添加新项目时我想开始一个新的动作模式来添加新项目,这个动作模式应该包含一个带文本框和按钮的简单布局,所以我创建了这个布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@+id/text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="text" >
</EditText>
<Button
android:id="@+id/addBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
所以现在我只需要在新的动作模式中将此布局设置为条形:
newItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
actionMode = startActionMode(new MyAction(ListEditor.this));
return true;
}
});
Run Code Online (Sandbox Code Playgroud)
在我的行动中:
private final class MyAction implements ActionMode.Callback {
...
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
View customNav = LayoutInflater.from(context).inflate(R.layout.add_item, null);
getSupportActionBar().setCustomView(customNav);
getSupportActionBar().setDisplayShowCustomEnabled(true);
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
所以基本上我需要来自sherlock示例的ActionModes和CustomNavigation之间的东西,但问题是它将布局设置为主条,而不是为打开操作的新条.
有什么建议?
所以我有一个Android 库,我希望其他人能够在使用它时轻松自定义其颜色.问题是颜色不仅仅是一个属性(如视图背景),但它更像是一个主题颜色(视图背景,文本颜色,按钮的笔触等)所以我是无法将其作为视图属性传递.所以我最终使用了a color reference并在样式,布局和drawable中使用它:
colors.xml:
<resources>
<attr name="color" format="reference" />
</resources>
Run Code Online (Sandbox Code Playgroud)
layout.xml:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/color">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/color"/>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="@style/LibraryTheme.TextAppearance"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
库项目中的styles.xml:
<style name="LibraryTheme.TextAppearance">
<item name="android:textColor">?attr/color</item>
<item name="colorControlNormal">?attr/color</item>
<item name="android:textColorHint">?attr/color</item>
<item name="colorControlActivated">?attr/color</item>
<item name="colorControlHighlight">?attr/color</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这很有效,当有人使用我的lib时,他必须声明他希望你在他的主题中使用的颜色:
app项目中的styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="color">@color/my_color</item>
</style>
Run Code Online (Sandbox Code Playgroud)
问题是这样的:我想用默认的配色方案来提供这个库.它现在可以通过2个选项执行:
第一个非常糟糕,因为我不能强迫用户使用特定的应用主题(如AppCompact.Light).第二个也不是那么好,因为我希望用户能够无缝地使用默认值,并且我需要在主题中设置几种颜色.
有没有其他方式你认为我可以让其他用户轻松玩颜色?
谢谢.
android android-custom-view android-theme android-view android-custom-attributes
我知道这个帖子,和我的问题一样.
但正如它在其中一条评论中所述 - API已更改为此,并且"message"属性现在被忽略.有没有办法用新API设置文本框内容?
这是我的代码:
protected void post() {
Bundle params = new Bundle();
params.putString("message", "my message here");
facebook.dialog(this, "feed", params, new DialogListener() {
@Override
public void onFacebookError(FacebookError e) {
}
@Override
public void onError(DialogError e) {
}
@Override
public void onComplete(Bundle values) {
}
@Override
public void onCancel() {
}
});
}
Run Code Online (Sandbox Code Playgroud)
谢谢.