Kindle Fire HD:电影比jpgs更亮

时间:2012-10-22 03:32:00

标签: android media-player android-mediaplayer kindle-fire brightness

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

可能在六种不同的设备上测试过。今天第七集:Kindle Fire HD。在这个设备上,电影都比相应的jpgs更亮。在所有其他设备上,它们完美匹配。什么可能导致这个或如何修复的想法?

(高清的另一个问题是电影开始播放的时间非常长。但这是另一个问题。)

编辑:这是我的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文件,但不知道如何。

1 个答案:

答案 0 :(得分:0)

根据此论坛帖子https://forums.developer.amazon.com/forums/thread.jspa?threadID=450#1780

,看起来像是设计的