Android MediaPlayer:视频搜索导致onSeekComplete被调用两次 [英] Android MediaPlayer: video seek causes onSeekComplete to be called twice

查看:85
本文介绍了Android MediaPlayer:视频搜索导致onSeekComplete被调用两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里做错了什么?我设置了onSeekCompleteListener,准备了一部电影,我进行了搜索.立即调用onSeekComplete.然后,经过一段延迟,我播放了电影.然后再次调用onSeekComplete!又为什么呢?这是我的代码:

What am I doing wrong here? I set up onSeekCompleteListener, I prepare a movie, I do a seek. Right away onSeekComplete is called. Then after a delay I play the movie. And then onSeekComplete is called again! Why again? Here is my code:

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

推荐答案

很遗憾,我无法在您的问题中添加评论,但是我遇到了同样的问题. 我还注意到,第一次调用onSeekComplete并输出currentMediaPostition()时,它返回的介质位置与通过seekTo(msec)调用的介质位置相同.很好.

Unfortunately I cannot add comments to your question, but I'm having the same problem. I also noticed that, when the onSeekComplete is called the first time and you output currentMediaPostition(), it returns the same media position as it was called through seekTo(msec); which is fine.

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

But the second call to onSeekComplete (when the media starts) will output an other value (up to multiple seconds more or even less).

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

So I think the second call comes from the start() method. If you raise the delay from 1000ms to 3000ms, the call comes also later..

这篇关于Android MediaPlayer:视频搜索导致onSeekComplete被调用两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆