媒体播放器暂停不起作用

时间:2013-07-05 11:49:42

标签: android media-player

点击线性布局后,我需要在与表面视图相关联的媒体播放器中暂停流式传输。 但是播放器没有暂停。(我正在模拟器中测试)。 这是代码

public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        Thread.setDefaultUncaughtExceptionHandler(onBlooey);

        setContentView(R.layout.main);

        surface = (TappableSurfaceView) findViewById(R.id.surface);
        surface.addTapListener(onTap);
        holder = surface.getHolder();

        holder.addCallback(this);
        holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

        topPanel = findViewById(R.id.top_panel);
        bottomPanel = findViewById(R.id.bottom_panel);

        timeline = (SeekBar) findViewById(R.id.timeline);
        timeline.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
                // TODO Auto-generated method stub
                if (player != null) {
                    if (player.isPlaying()) {
                        player.seekTo(progress);
                    } else {
                        player.start();
                        player.seekTo(progress);
                    }
                }

            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

        });

        media = (ImageButton) findViewById(R.id.media);
        media.setOnClickListener(onMedia);

        seekbarTopPanel = (LinearLayout) findViewById(R.id.seekbarTopPanel);

        playVideo();
        clearPanels(true);
        seekbarTopPanel.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                topPanel.setVisibility(View.VISIBLE);
                if (player != null) {
                    System.out.println("in player pause");
                    player.pause();
                }

            }
        });
    }



public void surfaceCreated(SurfaceHolder holder) {

        player.setDisplay(holder);
    }

private void playVideo() {
        try {
            media.setEnabled(false);

            if (player == null) {
                System.out.println("media player created");
                player = new MediaPlayer();
                player.setScreenOnWhilePlaying(true);
            } else {
                player.stop();
                player.reset();
            }
            // url="C:\\Users\\Sai Dinakar\\Downloads\\Relaxing Music & Beautiful Nature 6 1080p HD.mp3";
            Uri url = Uri.parse("android.resource://" + getPackageName() + "/"
                    + R.raw.nature);
            // player.setDataSource(url);
            player.setDataSource(getApplicationContext(), url);

            player.setAudioStreamType(AudioManager.STREAM_MUSIC);
            player.setOnPreparedListener(this);
            player.prepareAsync();
            // player.setOnBufferingUpdateListener(this);
            player.setOnCompletionListener(this);
            VideoTimerHandler videoTimerHandler = new VideoTimerHandler();
            videoTimerHandler.playVideoTimer();
        } catch (Throwable t) {
            Log.e(TAG, "Exception in media prep", t);

        }
    }

问题在于oncreate - > seekbarTopPanel.setOnClickListener(new OnClickListener()

暂停播放暂停,但视频仍未暂停。

0 个答案:

没有答案