简体   繁体   English

在Android上播放rtsp流

[英]play rtsp stream on Android

I need to play android rtsp stream for both video audio. 我需要同时播放两个视频音频的android rtsp流。 But no matter what I do they just don't start. 但是,无论我做什么,他们都没有开始。 The rstp stream for video is in .mp4 format and for audio it is in .mp3. 视频的rstp流采用.mp4格式,音频的rstp流采用.mp3。 The stream works fine when played in VLC and it shows the resolution which is 320X240. 在VLC中播放时,该流工作正常,并且显示的分辨率为320X240。 But here it just give the error which I have posted at the bottom. 但是这里只是给出我在底部发布的错误。 Also please tell how to stream an mp3 as there is no tutorial in the API Demos in android-sdk. 还请告诉我们如何流mp3,因为android-sdk中的API演示中没有教程。 The video works fine with Vitamio Library. 该视频在Vitamio Library上运行良好。 But I don't know how to customize it. 但是我不知道如何自定义它。

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);

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

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

ERROR: 01-05 21:10:59.640: ERROR/MediaPlayerDemo(15989): invalid video width(0) or height(0) 错误:01-05 21:10:59.640:ERROR / MediaPlayerDemo(15989):无效的视频宽度(0)或高度(0)

Change the onVideoSizeChanged(...) Function into:- 将onVideoSizeChanged(...)函数更改为:-

public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
        Log.d("onVideoSizeChanged: (%dx%d)", width, height);
        mVideoWidth = mp.getVideoWidth();
        mVideoHeight = mp.getVideoHeight();
        mVideoAspectRatio = mp.getVideoAspectRatio();
        if (mVideoWidth != 0 && mVideoHeight != 0)
            setVideoLayout(mVideoLayout, mAspectRatio);
    }
public void onVideoSizeChanged(MediaPlayer mp, int width, int height)
{
    if(width == 0 || height == 0) {
        return;
    }

    this.width = width;
    this.height = height;
    aspectRatio = width/height;

    startVideoPlayback();
}

I would advise you to do this. 我建议您这样做。

Inside the onPrepared method replace startVideoPlayback() with mediaPlayer.start() 在onPrepared方法内部,将startVideoPlayback()替换为mediaPlayer.start()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM