Android MediaPlayer:视频搜索导致onSeekComplete被调用两次

时间:2012-05-12 16:47:52

标签: android android-mediaplayer

我在这里做错了什么?我设置了onSeekCompleteListener,我准备了一部电影,我做了一个寻求。马上调用onSeekComplete。然后经过一段时间我就播放了这部电影。然后再次调用onSeekComplete!又为什么?这是我的代码:

package com.test.seek;

import java.io.IOException;

import android.app.Activity;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;

public class SeekTestActivity extends Activity implements SurfaceHolder.Callback, MediaPlayer.OnSeekCompleteListener {

    private SurfaceView sv;
    private MediaPlayer mp = new MediaPlayer();
    private static final String TAG = SeekTestActivity.class.getSimpleName();

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        sv = new SurfaceView(this);
        setContentView(sv);
        sv.getHolder().addCallback(this);
        sv.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        mp.setOnSeekCompleteListener(this);
        try {
            mp.setDataSource( this, Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.coverbutton_600x1024_05) );
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

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

    }

    @Override
    public void surfaceCreated(SurfaceHolder arg0) {
        mp.setDisplay( sv.getHolder() );
        Log.d(TAG,"preparing movie");
        try {
            mp.prepare();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Log.d(TAG,"seeking");
        mp.seekTo(0);
        final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                Log.d(TAG,"playing movie");
                mp.start();
            }
        }, 1000);

    }

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

    }

    @Override
    public void onSeekComplete(MediaPlayer mp) {
        Log.d(TAG,"seek complete");

    }
}

这是LogCat:

05-12 09:18:38.446: D/SeekTestActivity(3857): preparing movie
05-12 09:18:38.446: D/AwesomePlayer(3543): AwesomePlayer Not VPX decoder = **video/avc** and video is = 600X1024
05-12 09:18:38.446: D/OMX_CORE(3543): TIOMX_GetHandle
05-12 09:18:38.446: E/OMX_PROXYDEC(3543): ___INSISDE VIDEO DECODER PROXY WRAPPER__
05-12 09:18:38.571: D/OMXCodec(3543): Flash Clip: Profile: 77, Level: 31, Interlaced: 0, RefFrames: 2
05-12 09:18:38.571: D/OMXCodec(3543): Updated. H264 Component profile 2 level 512 NRefFrames 2
05-12 09:18:38.571: D/OMXCodec(3543): initOutputFormat WxH 600x1024 Padded 768x1120
05-12 09:18:38.571: D/AwesomePlayer(3543):  initRenderer_l 768x1120
05-12 09:18:38.571: D/AwesomePlayer(3543):  initRenderer_l 600x1024
05-12 09:18:38.571: D/OMXCodec(3543): CodecRecommended O/P BufferCnt[9]
05-12 09:18:38.571: D/AwesomePlayer(3543): Codec Recommended outputBuffer count 9
05-12 09:18:38.571: D/TIOverlay(1419): Enabling the OVERLAY[0]
05-12 09:18:38.571: I/Overlay-V4L2(1419): Openning /dev/video1
05-12 09:18:38.571: D/TIOverlay(1419): Creating overlay from W768/H1120/FMT33 ...
05-12 09:18:38.571: D/TIOverlay(1419): mZorderUsage[0] is assigned to 0
05-12 09:18:38.571: I/TIOverlay(1419): Setting position X65/Y0/W959/H600
05-12 09:18:38.571: D/TIOverlay(1419): REQUEST FOR LCD1
05-12 09:18:38.571: D/TIOverlay(1419): found Panel Id @ [0], displayname [lcd2]
05-12 09:18:38.571: D/TIOverlay(1419): found Display Manager @ [2], managername [2lcd]
05-12 09:18:38.571: I/TIOverlay(1419): Position/X65/Y0/W959/H600/R270/A255/Z1
05-12 09:18:38.571: I/TIOverlay(1419): Adjusted Position/X65/Y0/W600/H958
05-12 09:18:38.571: D/TIOverlay(3543): Num of Buffers = 2
05-12 09:18:38.571: D/TIOverlay(3543): LCD[0] NAME[lcd2]
05-12 09:18:38.571: D/TIOverlay(3543): LCD[0] PATH[/sys/devices/platform/omapdss/display0/enabled]
05-12 09:18:38.571: D/TIOverlay(3543): LCD[0] timings[46000,1024/160/150/10,600/12/20/3
05-12 09:18:38.571: D/TIOverlay(3543): ]
05-12 09:18:38.571: E/TIOverlay(3543): Can't open the file[/sys/devices/platform/omapdss/display1/name]
05-12 09:18:38.571: D/TIOverlay(3543): lcd name get failed (maybe because device has less displays than max allowed)
05-12 09:18:38.571: D/TIOverlay(3543): MANAGER[0] NAME[lcd]
05-12 09:18:38.571: D/TIOverlay(3543): MANAGER[1] NAME[tv]
05-12 09:18:38.579: D/TIOverlay(3543): MANAGER[2] NAME[2lcd]
05-12 09:18:38.579: D/TIHardwareRenderer(3543): Overlay Buffer Count [as recommneded] 9
05-12 09:18:38.579: D/TIOverlay(3543): overlay_resizeInput 768x1120 9
05-12 09:18:38.602: I/OMXCodec(3543): [OMX.TI.DUCATI1.VIDEO.DECODER] allocating 4 buffers of size 622592 on input port
05-12 09:18:38.633: I/OMXCodec(3543): [OMX.TI.DUCATI1.VIDEO.DECODER] allocating 9 buffers of size 6881280 on output port
05-12 09:18:38.641: D/SeekTestActivity(3857): seeking
05-12 09:18:38.657: I/ActivityManager(1419): Displayed com.test.seek/.SeekTestActivity: +358ms
05-12 09:18:38.657: I/LAB126(1481): StatusBarService hears intent. action: com.lab126.intent.TOP_WINDOW_CHANGED
05-12 09:18:38.657: I/LAB126(1481):  window changed
05-12 09:18:38.672: D/SeekTestActivity(3857): seek complete
05-12 09:18:38.688: I/TIOverlay(1419): Setting position X65/Y0/W899/H600
05-12 09:18:38.688: D/TIOverlay(1419): REQUEST FOR LCD1
05-12 09:18:38.688: D/TIOverlay(1419): found Panel Id @ [0], displayname [lcd2]
05-12 09:18:38.688: D/TIOverlay(1419): found Display Manager @ [2], managername [2lcd]
05-12 09:18:38.688: I/TIOverlay(1419): Position/X65/Y0/W899/H600/R270/A255/Z1
05-12 09:18:38.688: I/TIOverlay(1419): Adjusted Position/X65/Y0/W600/H898
05-12 09:18:38.727: D/dalvikvm(1481): GC_CONCURRENT freed 1095K, 51% free 3456K/7047K, external 2508K/2989K, paused 2ms+3ms
05-12 09:18:39.641: D/SeekTestActivity(3857): playing movie
05-12 09:18:39.696: D/Omap4ALSA(3543): open called for devices 00000002 in mode 0 channels 00000000...
05-12 09:18:39.719: I/Omap4ALSA(3543): Using ping-pong!
05-12 09:18:39.719: I/Omap4ALSA(3543): Buffer size: 4096
05-12 09:18:39.719: I/Omap4ALSA(3543): Latency: 92879
05-12 09:18:39.758: D/TIOverlay(3543): Crop Win/X32/Y24/W600/H1024
05-12 09:18:39.758: D/TIOverlay(3543): REQUEST FOR LCD1
05-12 09:18:39.758: D/TIOverlay(3543): found Panel Id @ [0], displayname [lcd2]
05-12 09:18:39.758: D/TIOverlay(3543): found Display Manager @ [2], managername [2lcd]
05-12 09:18:39.766: I/Omap4ALSA(3543): Initialized ALSA PLAYBACK device 'plughw:0,0'
05-12 09:18:39.766: E/AudioHardwareALSA(3543): RE-OPEN AFTER STANDBY:: took 70 msecs
05-12 09:18:39.774: D/SeekTestActivity(3857): seek complete

1 个答案:

答案 0 :(得分:1)

不幸的是我不能为你的问题添加评论,但我遇到了同样的问题。 我还注意到,当第一次调用onSeekComplete并输出currentMediaPostition()时,它会返回与通过seekTo(msec)调用相同的媒体位置;这很好。

但是第二次调用onSeekComplete(当媒体启动时)将输出另一个值(多达几秒甚至更多)。

所以我认为第二个调用来自start()方法。如果您将延迟时间从1000毫秒提高到3000毫秒,则呼叫也会稍后进行..