小编fad*_*den的帖子

纹理查看视频和位图显示

我有一个显示位图(占位符图像)的TextureView,当用户加载视频时,textureView应该显示视频.

我设法在纹理视图中播放视频并在纹理视图中显示位图,但是当按顺序完成时,我只得到一个黑屏.

在我的onSurfaceTextureAvailable方法中,我在表面视图上绘制一个位图,如下所示:

@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
    Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.ic_add_clip);
    Canvas canvas = lockCanvas();
    canvas.drawBitmap(bm, (width/2)-(bm.getWidth()/2), (height/2)-(bm.getHeight()/2), null);
    unlockCanvasAndPost(canvas);
}
Run Code Online (Sandbox Code Playgroud)

当用户从其库中选择视频时,我将Uri加载到媒体播放器中并将曲面设置为媒体播放器.但是仍然显示位图.我试图通过清除画布删除位图,它确实删除了位图,但纹理视图只是黑色,也不会显示视频.

public void setMediaPlayer(MediaPlayer mediaPlayer) {
    // Canvas canvas = lockCanvas();
    // canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
    // unlockCanvasAndPost(canvas);

    Surface s = new Surface(getSurfaceTexture());
    mMediaPlayer = mediaPlayer;
    mMediaPlayer.setSurface(s);
    mMediaPlayer.setOnPreparedListener(this);
}
Run Code Online (Sandbox Code Playgroud)

有些东西告诉我,用于显示视频的表面视图位于我在TextureAvailble上绘制的位图的后面.当我尝试清除画布时,我也清除了媒体播放器想要使用的表面.有解决方案吗

android android-canvas textureview android-bitmap

1
推荐指数
1
解决办法
5677
查看次数

Android Marshmallow:java.lang.RuntimeException:无法连接到相机服务

我在我的android应用程序中使用https://github.com/dlazaro66/QRCodeReaderView(QR码扫描程序)

我的主要权限如下:

<uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus"/>
Run Code Online (Sandbox Code Playgroud)

在Gradle中我有以下代码:

 compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.gurkhatech.schoolmanagement"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
Run Code Online (Sandbox Code Playgroud)

我已经用Java实现了代码:

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_qr);
        mQrCodeReaderView = (QRCodeReaderView)findViewById(R.id.qrdecoderview);
        mQrCodeReaderView.setOnQRCodeReadListener(this);

    }

    @Override
    public void onQRCodeRead(String text, PointF[] points) {
        Toast.makeText(getApplicationContext(),text,Toast.LENGTH_LONG).show();

    }

    @Override
    public void cameraNotFound() {

    }

    @Override
    public void QRCodeNotFoundOnCamImage() {

    }

    @Override
    protected void onResume() {
        super.onResume();
        mQrCodeReaderView.getCameraManager().startPreview();
    }

    @Override
    protected void onPause() {
        super.onPause(); …
Run Code Online (Sandbox Code Playgroud)

android qr-code android-camera android-6.0-marshmallow

1
推荐指数
1
解决办法
3938
查看次数

名为"i"的局部变量不能在此范围内声明,因为它会给"i"赋予不同的含义

我正在创建一个太空入侵者类型的游戏并遇到错误.错误发生在Update函数内,两个for循环内.一个用于检查有多少外星人活着,一个用于检查外星人是否到达屏幕底部.

这是代码中的主要错误

    if (rectShipBullet.Y + rectShipBullet.Height < 0)// Adding this will allow the player to fire a new bullet each time the player misses. If a minus symbol was used then the bullet would go off the screen far too early and not look realistic so the plus symbol is used instead.
                        ShipBulletVisible = "No";

                    int CountAliensAlive = 0;//Keeps track of how many aliens are alive.
                    for (int i = 0; i < rectSpaceInvader.Length; i++)
                    {
                        if (AlienAlive[i].Equals("Yes")) …
Run Code Online (Sandbox Code Playgroud)

c# xna

0
推荐指数
1
解决办法
1583
查看次数

将视频置于屏幕中央-Videoview Android

我有一个视频视图,播放某个视频,这是他的xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="match_parent">



Some other views


    <VideoView
        android:id = "@+id/video"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_gravity="center"
        android:layout_alignParentStart="true"
        />



</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我正在尝试将视频居中放置,但是无论何时我播放视频,它都不会出现在中心位置,并且位置会有所不同,具体取决于视频,如何将其居中?

android android-layout android-videoview

-1
推荐指数
1
解决办法
3378
查看次数