gpt4 book ai didi

android - RTMP android 后处理

转载 作者:太空狗 更新时间:2023-10-29 14:27:25 33 4
gpt4 key购买 nike

我正在尝试实现来自 http://www.aftek.com/afteklab/aftek-RTMP-library.shtml 的库从 red5 服务器流式传输实时视频。

在服务器上,我正在使用 simpleBroadcaster,我想将它流式传输到 android 手机。

我的代码:

package com.cu.reader;

import java.nio.channels.FileChannel;
import java.util.Map;
import com.al.rtmp.client.RtmpClient;
import com.al.rtmp.client.RtmpStream;
import com.al.rtmp.client.RtmpStreamFactory;
import com.al.rtmp.client.data.MetaData;
import com.al.rtmp.client.data.RTMPData;
import com.al.rtmp.client.data.VideoCodec;
import com.al.rtmp.message.Metadata;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class StreamreaderActivity extends Activity implements RtmpClient {
RtmpStream stream = null;
Boolean connected = false;
String server = "rtmp://216.224.181.197/oflaDemo/";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
stream = RtmpStreamFactory.getRtmpStream();
stream.setClient(this);
stream.connect(server);
}
@Override
public void streamCreated() {
Log.i("stream","Connected!");

connected = true;
stream.setPlayName("red5StreamDemo");
stream.play();

}
@Override
public byte[] getWriteData(int length) {
// TODO Auto-generated method stub
return null;
}
@Override
public void invoke(String arg0, Object... arg1) {
// TODO Auto-generated method stub
;
}
@Override
public void onDataReceived(RTMPData rtmpData) {
MetaData metaData = rtmpData.getMetaData();
VideoCodec vc = metaData.getVideoCodec();
}
@Override
public void onError(Exception ex) {
Log.e("ClientException", " Some exception occurred." + ex.getMessage());
ex.printStackTrace();
}
@Override
public void onMetaDataReceived(Map map) {
Log.i("code","METADATA:" + map);

}
@Override
public void onResult(String method, Object... arg1) {
Log.i("result","METADATA:" + method);

}
@Override
public void onStatus(String code) {
Log.i("code",code);
}

}

我总是在 onStatus 函数中收到 NetStream.Play.StreamNotFound。

谢谢

最佳答案

您收到 NetStream.Play.StreamNotFound 错误,因为在 red5 应用程序上不存在此类流。

我做了快速 as3 测试来检查:

package {

import flash.display.Sprite;
import flash.events.AsyncErrorEvent;
import flash.events.IOErrorEvent;
import flash.events.NetStatusEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;

public class LearnWowzaClient extends Sprite {

private var nc:NetConnection;
private var video:Video = new Video();

public function LearnWowzaClient() {

nc = new NetConnection();
nc.client = this;
nc.addEventListener(NetStatusEvent.NET_STATUS, onNet);
nc.connect("rtmp://216.224.181.197/oflaDemo/");
}

private function onNet(event:NetStatusEvent):void {
trace(event);
trace(event.info.code);
switch (event.info.code) {
case "NetConnection.Connect.Success":
tryPlayStream();
break;
}
}

private function tryPlayStream():void {
trace("playStream");
var ns:NetStream = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
ns.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError);

ns.play("red5StreamDemo");
video.attachNetStream(ns);
}

public function onBWCheck(parameter:Object = null):void {
trace("onBWCheck p=" + parameter);
}

public function onBWDone(parameter:Object = null):void {
trace("onBWDone p=" + parameter);
}

private function onIOError(event:IOErrorEvent):void {
trace("onIOError");
}

private function onAsyncError(event:AsyncErrorEvent):void {
trace("onAsyncError");
}

private function onNetStatus(event:NetStatusEvent):void {
trace("onNetStatus ", event.info.code);
}
}
}

我也收到 NetStream.Play.StreamNotFound 错误。你能显示 red5 应用程序代码吗?

关于android - RTMP android 后处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10743369/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com