2

我一直在开发一个用户触摸屏幕开始电影的应用程序。屏幕图像是电影的第一帧。一旦触摸发生,电影就会播放。我通过将第一帧的 jpg 放在电影前面,然后在我认为电影正在播放时删除 jpg 来做到这一点。(弄清楚何时发生这种情况是不可能的,但这是另一个问题。在旧设备上,如果你过早删除图像,你会变黑。)

在大概六种不同的设备上进行了测试。今天第七个:Kindle Fire HD。在此设备上,电影都比相应的 jpg 更亮。在所有其他设备上,它们完美匹配。有什么想法可能导致此问题或如何解决?

(HD 的另一个问题是电影需要很长时间才能开始播放。但这是另一个问题。)

编辑:这是我的 main.xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <ImageView
        android:id="@+id/iv"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
    <VideoView
        android:id="@+id/vv" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
</FrameLayout>

这是代码:

public class VideoTestActivity extends Activity implements SurfaceHolder.Callback, OnPreparedListener, OnCompletionListener {
private VideoView vv;
private ImageView iv;
private Bitmap b;
private MediaPlayer mp = new MediaPlayer();
private static final String TAG = VideoTestActivity.class.getSimpleName();
private volatile boolean prepared = false;
private volatile boolean readytoplay = false;
private volatile boolean playing = false;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main);
    iv = (ImageView)findViewById(R.id.iv);
    iv.bringToFront();
    vv = (VideoView)findViewById(R.id.vv);
    b = BitmapFactory.decodeResource(getResources(), R.drawable.babyblack);
    iv.setBackgroundColor( 0xFFDFA679 );
    vv.getHolder().addCallback(this);
    mp.setOnPreparedListener( this );
    mp.setOnCompletionListener( this );
    try {
        mp.setDataSource( this, Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.ape) );
    } catch (IllegalArgumentException e) {
        Log.d(TAG,"illegal argument exception on set data source");
        e.printStackTrace();
    } catch (SecurityException e) {
        Log.d(TAG,"security exception on set data source");
        e.printStackTrace();
    } catch (IllegalStateException e) {
        Log.d(TAG,"illegal state exception on set data source");
        e.printStackTrace();
    } catch (IOException e) {
        Log.d(TAG,"IO exception on set data source");
        e.printStackTrace();
    }

}

@Override
public boolean onTouchEvent(MotionEvent event) {
    float dx, dy;
    Log.d(TAG,"touch event");
    if ( !playing && event.getAction() == MotionEvent.ACTION_UP ) {
        Log.d(TAG,"action up");
        if ( prepared ) {
            playing = true;
            Log.d(TAG,"hardware accelerated: iv="+iv.isHardwareAccelerated()+", vv="+vv.isHardwareAccelerated());
            mp.start();
            Log.d(TAG, "playing video in onTouch callback");
            Log.d(TAG,"hardware accelerated: iv="+iv.isHardwareAccelerated()+", vv="+vv.isHardwareAccelerated());
        } else
            readytoplay = true;
    }
    return true;
}

@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
    // TODO Auto-generated method stub

}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    // TODO Auto-generated method stub
    Log.d(TAG,"surface is created");
    mp.setDisplay( vv.getHolder() );
    try {
        mp.prepareAsync();
    } catch (IllegalArgumentException e) {
        Log.d(TAG,"illegal argument exception on prepare");
        e.printStackTrace();
    } catch (SecurityException e) {
        Log.d(TAG,"security exception on prepare");
        e.printStackTrace();
    } catch (IllegalStateException e) {
        Log.d(TAG,"illegal state exception on prepare");
        e.printStackTrace();
    }
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    // TODO Auto-generated method stub
}

@Override
public void onPrepared(MediaPlayer mp) {
    Log.d(TAG,"video is prepared");
    prepared = true;
    if ( readytoplay ) {
        playing = true;
        mp.start();
        iv.setVisibility( View.GONE );
        Log.d(TAG,"playing video from prepared callback");
    }
}

@Override
public void onCompletion(MediaPlayer arg0) {
    Log.d(TAG,"video is done");
    playing = false;
    iv.setVisibility( View.VISIBLE );
}}

我将 ImageView 更改为没有图像,而只有纯色背景。您需要的唯一数据文件是 mp4 电影。当您触摸屏幕时,电影就会播放,隐藏在 ImageView 后面。当我触摸它时屏幕立即变亮(mp.start() 发生),然后电影开始播放,逐渐变暗,然后再次变亮,最后在电影完成时稳定下来。

我试过硬件加速,没有硬件加速;没有不同。我尝试将 Kindle Fire HD 插入,而不是插入;没有不同。

我会发布我正在使用但不知道如何发布的 2 秒 mp4 文件。

4

1 回答 1

0

看起来它是设计使然,根据这个论坛帖子 - https://forums.developer.amazon.com/forums/thread.jspa?threadID=450#1780

于 2012-12-14T19:13:24.457 回答