1

我想播放实时流,VideoView但我收到错误是什么错误:

04-21 21:13:27.326: D/MediaPlayer(29449): Couldn't open file on client side, trying server side
04-21 21:13:27.529: D/dalvikvm(29449): GC_CONCURRENT freed 81K, 2% free 9218K/9328K, paused 5ms+3ms, total 28ms
04-21 21:14:17.654: E/MediaPlayer(29449): error (1, -1004)
04-21 21:14:17.654: E/MediaPlayer(29449): Error (1,-1004)
04-21 21:14:17.654: D/VideoView(29449): Error: 1,-1004

我播放直播的代码:

public  class VideoStreamingActivity  extends Activity implements OnPreparedListener,OnErrorListener{

    private Vibrator vibrator;
    private boolean readyToPlay;
    private ProgressBar progress;
    private ProgressDialog loading;
    private TextView mediaTimeElapsed;
    private TextView mediaTime;
    private TextView mediaInfo;
    private Button play;
    private Button stop;
    private String url;
    private VideoView vvStreaming;
    private CountDownTimer timer;

    /** Called when the activity is first created.*/
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(R.layout.activity_video_streaming);

        //variables init
        vvStreaming = (VideoView)findViewById(R.id.vvStreaming);



        url ="http://www.ted.com/talks/download/video/8584/talk/761";
        play = (Button)findViewById(R.id.btnPlay);
        stop = (Button)findViewById(R.id.btnPause);

        mediaInfo = (TextView) findViewById(R.id.tvMediaInfo);
        mediaTime = (TextView)findViewById(R.id.tvTime);
        mediaTimeElapsed = (TextView)findViewById(R.id.tvTimeElapsed);

        progress = (ProgressBar) findViewById(R.id.progressBar1);
        loading = new ProgressDialog(this);
        loading.setMessage("Loading...");

        vibrator =   (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);

        //flag indicating that content is ready for playback
        readyToPlay = false;

        // listeners for VideoView:

        //vvStreaming.setOnPreparedListener(this);
        //vvStreaming.setOnErrorListener(this);

        vvStreaming.setVideoURI(Uri.parse(url));
        vvStreaming.setMediaController(new MediaController(this));
        vvStreaming.start();



    }

    @Override
    public boolean onError(MediaPlayer mp, int what, int extra) {
        loading.hide();
        return false;
    }

    @Override
    public void onPrepared(MediaPlayer mp) {
        Log.d(this.getClass().getName(), "prepared");
        mp.setLooping(true);
        loading.hide();



        //onVideoSizeChangedListener declaration
        /*  mp.setOnVideoSizeChangedListener(new OnVideoSizeChangedListener() {
            @Override
            public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
                if(width!=0 && height!=0) {
                    Log.d(this.getClass().getName(), "logo off");
                    logo.setVisibility(ImageView.INVISIBLE);
                } else {
                    Log.d(this.getClass().getName(), "logo on");
                    logo.setVisibility(ImageView.VISIBLE);
                }               
            }
        });*/


        //onBufferingUpdateListener declaration
        mp.setOnBufferingUpdateListener(new OnBufferingUpdateListener()
        {
            // show updated information about the buffering progress
            @Override
            public void onBufferingUpdate(MediaPlayer mp, int percent) {
                Log.d(this.getClass().getName(), "percent: " + percent);
                progress.setSecondaryProgress(percent);
            }
        });

        //onSeekCompletionListener declaration
        mp.setOnSeekCompleteListener(new OnSeekCompleteListener() {

            //show current frame after changing the playback position
            @Override
            public void onSeekComplete(MediaPlayer mp) {
                if(mp.isPlaying()) {
                    //  playMedia(null);
                    //  playMedia(play);
                } else {
                    //  playMedia(null);
                    //  playMedia(play);
                    //  playMedia(null);
                }
                //  mediaTimeElapsed.setText(countTime(vvStreaming.getCurrentPosition()));
            }
        });

        mp.setOnCompletionListener(null);

        readyToPlay = true;
        int time = vvStreaming.getDuration();
        int time_elapsed = vvStreaming.getCurrentPosition();
        progress.setProgress(time_elapsed);

        timer = new CountDownTimer(time, 500) {

            @Override
            public void onTick(long millisUntilFinished) {
                //  mediaTimeElapsed.setText(countTime(vvStreaming.getCurrentPosition()));
                float a = vvStreaming.getCurrentPosition();
                float b = vvStreaming.getDuration();
                progress.setProgress((int)(a/b*100));
            }

            @Override
            public void onFinish() {
                //  stopMedia(null);

            }
        };
        //onTouchListener declaration
        progress.setOnTouchListener(new OnTouchListener() {

            // enables changing of the current playback position
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                ProgressBar pb = (ProgressBar) v;

                int newPosition = (int) (100 * event.getX() / pb.getWidth());
                if (newPosition > pb.getSecondaryProgress()) {
                    newPosition = pb.getSecondaryProgress();
                }

                switch (event.getAction()) {
                // update position when finger is DOWN/MOVED/UP
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_MOVE:
                case MotionEvent.ACTION_UP:
                    pb.setProgress(newPosition);
                    vvStreaming.seekTo((int) newPosition * vvStreaming.getDuration() / 100);
                    break;
                }
                return true;
            }
        });
    }
}
4

1 回答 1

1

检查您的清单用户权限:

<uses-permission android:name="android.permission.INTERNET" />
于 2013-05-21T15:21:31.060 回答