【问题标题】:Android audio/video Streaming is not working for Wowza serverAndroid 音频/视频流不适用于 Wowza 服务器
【发布时间】:2016-02-10 13:44:33
【问题描述】:

我想使用 Wowza 服务器实现视频流。那么,是否有任何关于 Wowza 如何在 Android 设备上工作的教程?

视频存储在服务器端。因此,使用 URL 获取视频并在 Android 上播放。我尝试了一些示例,但出现错误,“抱歉,无法播放此视频”。我正在使用 URL enter code heredefinst/mp4:amazons3/XXX/XXX_42u9Ug_MP4Akon-Beautifulft.ColbyO%27Donis%2CKardinalOffishall(1).mp4/manifest.f4m">http://XXXX.amazonaws.com/vods3/定义/mp4:amazons3/XXX/XXX_42u9Ug_MP4Akon-Beautifulft.ColbyO%27Donis%2CKardinalOffishall(1).mp4/manifest.f4m。

以下是源代码。

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    mVideoView = (VideoView) findViewById(R.id.surface_view);

    mPath = (EditText) findViewById(R.id.path);
    mPath.setText("http://XXXX.amazonaws.com/vods3/_definst_/mp4:amazons3/XXX/XXXX_42u9Ug_MP4Akon-Beautifulft.ColbyO%27Donis%2CKardinalOffishall(1).mp4/manifest.f4m");

    mPlay = (ImageButton) findViewById(R.id.play);
    mPause = (ImageButton) findViewById(R.id.pause);
    mReset = (ImageButton) findViewById(R.id.reset);
    mStop = (ImageButton) findViewById(R.id.stop);

    mPlay.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            playVideo();
        }
    });
    mPause.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            if (mVideoView != null) {
                mVideoView.pause();
            }
        }
    });
    mReset.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            if (mVideoView != null) {
                mVideoView.seekTo(0);
            }
        }
    });
    mStop.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            if (mVideoView != null) {
                current = null;
                mVideoView.stopPlayback();
            }
        }
    });
    runOnUiThread(new Runnable() {
        public void run() {
            playVideo();

        }

    });
}

private void playVideo() {
    try {
        final String path = mPath.getText().toString();
        Log.v(TAG, "path: " + path);
        if (path == null || path.length() == 0) {
            Toast.makeText(VideoStreamingDemo.this,
                    "File URL/path is empty", Toast.LENGTH_LONG).show();

        } else {
            // If the path has not changed, just start the media player
            if (path.equals(current) && mVideoView != null) {
                mVideoView.start();
                mVideoView.requestFocus();
                return;
            }
            current = path;
            mVideoView.setVideoPath(getDataSource(path));
            mVideoView.start();
            mVideoView.requestFocus();

        }
    } catch (Exception e) {
        Log.e(TAG, "error: " + e.getMessage(), e);
        if (mVideoView != null) {
            mVideoView.stopPlayback();
        }
    }
}

private String getDataSource(String path) throws IOException {
    if (!URLUtil.isNetworkUrl(path)) {
        return path;
    } else {
        URL url = new URL(path);
        URLConnection cn = url.openConnection();
        cn.connect();
        InputStream stream = cn.getInputStream();
        if (stream == null)
            throw new RuntimeException("stream is null");
        File temp = File.createTempFile("mediaplayertmp", "dat");
        temp.deleteOnExit();
        String tempPath = temp.getAbsolutePath();
        FileOutputStream out = new FileOutputStream(temp);
        byte buf[] = new byte[128];
        do {
            int numread = stream.read(buf);
            if (numread <= 0)
                break;
            out.write(buf, 0, numread);
        } while (true);
        try {
            stream.close();
        } catch (IOException ex) {
            Log.e(TAG, "error: " + ex.getMessage(), ex);
        }
        return tempPath;
    }
}

【问题讨论】:

    标签: android video wowza


    【解决方案1】:

    在安卓设备上播放视频使用“RTSP”,url格式为

    rtsp://wowzaserveripaddress:1935/applicationname/mp4:directoryname/videofilename.mp4
    

    rtsp://wowzaserveripaddress:1935/applicationname/mp4:videofilename.mp4
    

    举例

    rtsp://192.168.1.11:1935/vod/mp4:sample.mp4
    

    确保您的 wowza 服务器在测试之前正在运行

    在你的原生 android 播放器或 MXPlayer 中试试这个

    【讨论】:

      【解决方案2】:

      RTSP 真是让人头疼 尝试 [http://server_ip:1935/vod/definst/'文件夹名'/mp4:'视频名'.mp4/playlist.m3u8] 例如:我在“趋势”文件夹中的视频名称“camness.mp4”。那么我的网址是 [http://server_ip:1935/vod/definst/trend/mp4:camness.mp4/playlist.m3u8]

      【讨论】:

        猜你喜欢
        • 2011-12-19
        • 2013-03-30
        • 1970-01-01
        • 1970-01-01
        • 2013-03-05
        • 2017-07-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多