需要明确的重要一点是,您想到了什么样的发展。如果您只是想在您的应用程序中显示视频流,您应该为主要活动采用用户界面,该界面将仅包含 VideoView 类的实例。VideoView 类有很多可以调用的方法来管理视频的播放。
给 VideoView 配置要播放的视频的路径,然后开始播放。然后选择VideoPlayerActivity.java文件并修改 OnCreate() 方法,如下所示:
package com.example.videoplayer;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.VideoView;
public class VideoPlayerActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_player);
final VideoView videoView =
(VideoView) findViewById(R.id.videoView1);
videoView.setVideoPath(
"http://www.ebookfrenzy.com/android_book/movie.mp4");
videoView.start();
}
.
.
.
}
本质上,您拥有的是用于 App 用户界面的 Android SDK,这意味着您可以使用不同的选择在 UI 层下实际呈现视频流。
将您现有的应用程序从平板电脑或手机迁移到智能电视也是可以非常顺利地实现的。必须调整一些东西 - 例如通常用于智能电视的触摸屏可能不是一个选项。

相反,您应该将onkeyDown视为一种更可靠的方法来为您的应用程序输入交互:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_MEDIA_PLAY:{
if (!mPlaying) {
startSlideShow();
}
mPlaying = true;
break;
}
case KeyEvent.KEYCODE_MEDIA_PAUSE:{
mPlaying = false;
showStatusToast(R.string.slideshow_paused);
}
}
return super.onKeyDown(keyCode, event);
}
作为 Android Smart Google TV API 的一部分,您还可以针对更大的屏幕分辨率进行必要的调整:
// Get the source image's dimensions
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; // this does not download the actual image, just downloads headers.
BitmapFactory.decodeFile(IMAGE_FILE_URL, options);
int srcWidth = options.outWidth; // actual width of the image.
int srcHeight = options.outHeight; // actual height of the image.
// Only scale if the source is big enough. This code is just trying to fit a image into a certain width.
if(desiredWidth > srcWidth)
desiredWidth = srcWidth;
// Calculate the correct inSampleSize/scale value. This helps reduce memory use. It should be a power of 2.
int inSampleSize = 1;
while(srcWidth / 2 > desiredWidth){
srcWidth /= 2;
srcHeight /= 2;
inSampleSize *= 2;
}
float desiredScale = (float) desiredWidth / srcWidth;
// Decode with inSampleSize
options.inJustDecodeBounds = false; // now download the actual image.
options.inDither = false;
options.inSampleSize = inSampleSize;
options.inScaled = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888; // ensures the image stays as a 32-bit ARGB_8888 image.
// This preserves image quality.
Bitmap sampledSrcBitmap = BitmapFactory.decodeFile(IMAGE_FILE_URL, options);
// Resize
Matrix matrix = new Matrix();
matrix.postScale(desiredScale, desiredScale);
Bitmap scaledBitmap = Bitmap.createBitmap(sampledSrcBitmap, 0, 0,
sampledSrcBitmap.getWidth(), sampledSrcBitmap.getHeight(), matrix, true);
sampledSrcBitmap = null;
// Save
FileOutputStream out = new FileOutputStream(LOCAL_PATH_TO_STORE_IMAGE);
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
scaledBitmap = null;
您还可以轻松地将您的液晶电视转换为智能电视,然后开始播放和测试您的谷歌电视应用程序的行为方式。为此,您只需将手放在适配器套件中。
事实上,联想正在发布一款同样运行Android的 28 英寸 4K 显示器(ThinkVision 28) ,允许您运行所有常用的流媒体应用程序,Kogan也在做同样的事情。

在玩小玩意的过程中更进一步,您甚至可以在电视上使用 MHL HDMI 连接您的手机或将其用作电脑。

因此,与MHL 3.0 一起使用的 Android 进行 4K 视频输出已成为现实,优秀的开发人员已经可以根据所使用的设备使他们的应用程序具有必要的分辨率和输入调整。
如果您主要关心的是提高性能和优化视频流,您可以考虑以下选项:
- NDK:您决定使用一些库或实现您自己的程序,该程序实际上是用 C++ 制作的,以优化视频流。
- RenderScript:它使用 C99 语法和最终编译为本机代码的新 API 。虽然这种语法是众所周知的,但使用这个系统有一个学习曲线,因为 API 不是。
- OpenCL:用于图形加速,并提供许多用于 3D 渲染和视频流高性能的工具。

事实上,OpenCL 中的代码类似于 C/C++:
for (int yy=-filterWidth; yy<=filterWidth; ++yy)
{
for (int xx=-filterWidth; xx<=filterWidth; ++xx)
{
int thisIndex = (y + yy) * width + (x + xx);
float4 currentPixel = oneover255 *convert_float4(srcBuffer[thisIndex]);
float domainDistance = fast_distance((float)(xx), (float)(yy));
float domainWeight = exp(-0.5f * pow((domainDistance/sigmaDomain),2.0f));
float rangeDistance = fast_distance(currentPixel.xyz, centerPixel.xyz);
float rangeWeight = exp(-0.5f * pow((rangeDistance/sigmaRange),2.0f));
float totalWeight = domainWeight * rangeWeight ;
normalizeCoeff += totalWeight;
sum4 += totalWeight * currentPixel;
}
}
在 ARM 微处理器功能方面,值得一提的是用于 Android 机顶盒的 Sigma Designs SMP8756 ARM,旨在解决完整的高效视频编码 ( HEVC ) 功能。
要调整图像/视频的大小,您需要应用双线性过滤。双线性插值是使用隔行扫描视频帧中的每个中间场来生成全尺寸目标图像的过程。使用场上的所有奇数行或所有偶数行。然后在行之间和相邻像素之间执行插值,以生成用于逐行扫描输出的完整非隔行帧。

为了实现根据您需要的大小正确调整图像,有很多很好的算法可以用于此目的,例如一些用于图像缩放的 OpenCL 功能,同样对于本机 C++,其他选项也可用。