0

所以我对 Google TV 的编程感兴趣已经有一段时间了,并且刚刚开始涉足它。

我的第一个个人项目是创建一个简单的媒体播放器和文件浏览器,因为默认的媒体播放器太糟糕了。它在 Android 模拟器(版本 12)上完美运行,但是当我将它安装到我的 Google Revue 中时,我发现自己面临两个主要问题。

1) 播放器将始终按字母顺序播放第一部电影,无论选择哪个电影文件(所有格式和路径都正确。URI 加载到 setDataSource/setVideoPath 中)

2)每当我尝试快进一部电影时,它会按字母顺序跳到下一部电影

我在这里使用了来自 android 开发网站的 mediaplayer 和 videoview 示例:http: //developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/media/index.html 以及默认的 action_view 意图,但每一个都有完全相同的问题。这部电影将在模拟器上 100% 正常播放,但在 Google Revue 上具有完全不同的默认设置。

有没有人遇到过这个问题或者知道我能做什么/我可以去哪里解决它?

编辑

这是我调用活动的代码:

Intent intent = new Intent(getBaseContext(), myMediaPlayer.class);
intent.putExtra("PATH_ID", path);
startActivity(intent);

这是我运行 mediaPlayer 的代码。(几乎是网站代码的精确副本)

public class myMediaPlayer extends Activity implements
    OnBufferingUpdateListener, OnCompletionListener,
    OnPreparedListener, OnVideoSizeChangedListener, SurfaceHolder.Callback {

private static final String TAG = "MediaPlayerDemo";
private int mVideoWidth;
private int mVideoHeight;
private MediaPlayer mMediaPlayer;
private SurfaceView mPreview;
private SurfaceHolder holder;
private String path;
private String extras;

private boolean mIsVideoSizeKnown = false;
private boolean mIsVideoReadyToBePlayed = false;

/**
 * 
 * Called when the activity is first created.
 */
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.mediaplayer);
    mPreview = (SurfaceView) findViewById(R.id.surface);
    holder = mPreview.getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    extras = getIntent().getExtras().getString("PATH_ID");;

}

private void playVideo(String filePath) {
    doCleanUp();
    try {


        path = filePath;
        // Create a new media player and set the listeners
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setDataSource(path);
        mMediaPlayer.setDisplay(holder);
        mMediaPlayer.prepare();
        mMediaPlayer.setOnBufferingUpdateListener(this);
        mMediaPlayer.setOnCompletionListener(this);
        mMediaPlayer.setOnPreparedListener(this);
        mMediaPlayer.setOnVideoSizeChangedListener(this);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);


    } catch (Exception e) {
        Log.e(TAG, "error: " + e.getMessage(), e);
    }
}

public void onBufferingUpdate(MediaPlayer arg0, int percent) {
    Log.d(TAG, "onBufferingUpdate percent:" + percent);

}

public void onCompletion(MediaPlayer arg0) {
    Log.d(TAG, "onCompletion called");
}

public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
    Log.v(TAG, "onVideoSizeChanged called");
    if (width == 0 || height == 0) {
        Log.e(TAG, "invalid video width(" + width + ") or height(" + height + ")");
        return;
    }
    mIsVideoSizeKnown = true;
    mVideoWidth = width;
    mVideoHeight = height;
    if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
        startVideoPlayback();
    }
}

public void onPrepared(MediaPlayer mediaplayer) {
    Log.d(TAG, "onPrepared called");
    mIsVideoReadyToBePlayed = true;
    if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
        startVideoPlayback();
    }
}

public void surfaceChanged(SurfaceHolder surfaceholder, int i, int j, int k) {
    Log.d(TAG, "surfaceChanged called");

}

public void surfaceDestroyed(SurfaceHolder surfaceholder) {
    Log.d(TAG, "surfaceDestroyed called");
}


public void surfaceCreated(SurfaceHolder holder) {
    Log.d(TAG, "surfaceCreated called");
    playVideo(extras);


}

@Override
protected void onPause() {
    super.onPause();
    releaseMediaPlayer();
    doCleanUp();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    releaseMediaPlayer();
    doCleanUp();
}

private void releaseMediaPlayer() {
    if (mMediaPlayer != null) {
        mMediaPlayer.release();
        mMediaPlayer = null;
    }
}

private void doCleanUp() {
    mVideoWidth = 0;
    mVideoHeight = 0;
    mIsVideoReadyToBePlayed = false;
    mIsVideoSizeKnown = false;
}

private void startVideoPlayback() {
    Log.v(TAG, "startVideoPlayback");
    holder.setFixedSize(mVideoWidth, mVideoHeight);
    mMediaPlayer.start();
}

}

作为替代方案,我尝试像这样使用默认播放器:

Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(aDirectory.getAbsolutePath())), "video/*");
startActivity(intent);

但它总是按字母顺序播放文件夹中的第一个视频,而不是选定的视频

4

1 回答 1

0

关于快速转发,请查看:https ://developers.google.com/tv/android/docs/gtv_media_keys

对于第一个问题,您可能会发现https://developers.google.com/tv/android/docs/gtv_displayguide#NavigationFocus很有帮助。

于 2012-12-12T22:26:07.553 回答