This is a simple actionscript3 web cam player.
The player do both subscribe and publish video.
You can compile the code using flexbuilder.
Enjoy! Let me know if you actionscript2 player
Main class :
package liveplayer {
import flash.display.Sprite;
import flash.media.Video;
import lib.StreamPlayer;
public class liveplayer extends Sprite
{
public function liveplayer()
{
// TODO: move this to UI class
var vid:Video = new Video(320,240);
this.addChild (vid);
var stPlayer:StreamPlayer = new StreamPlayer(vid);
stPlayer.initialize_pub();
stPlayer.initialize_subscribe();
}
}
}
package lib{
// Player class
import flash.media.Camera;
import flash.media.Microphone;
import flash.media.Video;
import flash.net.*;
import flash.events.*;
import lib.Config;
public class StreamPlayer{
private var play_nc:NetConnection;
private var play_ns:NetStream;
private var pub_nc:NetConnection;
private var pub_ns:NetStream;
private var stat:Number;
private var myCamera:Camera = new Camera();
private var myMic:Microphone = new Microphone();
private var vidObj:Video;
public function StreamPlayer(vid:Video){
this.vidObj=vid;
}
public function initialize_subscribe():void{
// Get the camera
//myMic=Microphone.get();
// Connect to oflaDemo demo application in red5 server
play_nc = new NetConnection();
// Should be configurable
trace(Config.streamingURL);
play_nc.addEventListener(NetStatusEvent.NET_STATUS, sub_netStatus);
play_nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, netSecurityError);
play_nc.connect(Config.streamingURL);
}
function sub_netStatus(event:NetStatusEvent):void {
trace("netStatus: " + event);
var info:Object = event.info;
trace(info.code);
// lots more code here...
if (info.code == "NetConnection.Connect.Success") {
// Publish video from the camera to the red5 server
play_ns = new NetStream(play_nc);
this.subscribe();
}
else{
trace("error");
}
}
private function netSecurityError(event:SecurityErrorEvent):void {
trace("netSecurityError: " + event);
}
public function initialize_pub():void{
// Get the camera
myCamera = Camera.getCamera();
//vidObj.attachCamera(myCamera);
myMic=Microphone.getMicrophone();
// Connect to oflaDemo demo application in red5 server
pub_nc = new NetConnection();
NetConnection.prototype.onBWDone = function(p_bw) {
trace("onBWDone: ");
}
pub_nc.addEventListener(NetStatusEvent.NET_STATUS, pub_netStatus);
pub_nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, netSecurityError);
// Should be configurable
pub_nc.connect(Config.streamingURL);
trace(Config.streamingURL);
}
// publish connection status callback
function pub_netStatus(event:NetStatusEvent):void {
trace("netStatus: " + event);
var info:Object = event.info;
trace(info.code);
// lots more code here...
if (info.code == "NetConnection.Connect.Success") {
// Publish video from the camera to the red5 server
pub_ns = new NetStream(pub_nc);
this.publish();
}
else{
trace("error");
}
}
public function publish():void{
pub_ns.attachAudio(myMic);
pub_ns.attachCamera(myCamera);
pub_ns.publish(Config.stPubPoint, "live");
}
public function subscribe():void{
play_ns.play(Config.stPubPoint);
vidObj.attachNetStream(play_ns);
}
public function muteAudio():void{
//myMic.muted=true;
}
public function startAudio():void{
}
public function start_stop_subscribe():void{
play_ns.pause();
}
public function start_stop_pub():void{
pub_ns.pause();
}
}// End of class
}
package lib {
import lib.QueryString;
public class Config{
//public function Config(){
// Default value;
/* streamingURL= _root.streamingURL ? _root.streamingURL : "rtmp://127.0.0.1/oflaDemo";
messHost=_root.messHost ? _root.messHost : "127.0.0.1";
messPort=_root.messPort ? _root.messPort : 8081;
stPubPoint=_root.stPubPoint ? _root.stPubPoint : "example";
pubID=_root.pubID ? _root.pubID : "himu";
pageURL=_root.pageURL ? _root.pageURL : "http://test.com";
*/
// This should be intialized from the URL
public static var qs:QueryString= new QueryString;
//public static var streamingURL:String=qs.parameters('streamingURL');
//public static var stPubPoint:String=qs.parameters('stPubPoint');
public static var streamingURL:String="rtmp://yourip/oflaDemo";
public static var stPubPoint:String="example";
}
}
Wednesday, April 2, 2008
Sunday, March 23, 2008
Saturday, December 8, 2007
Djhango newform
A simple tutorial about basic newform
#create a form
from django import newforms as forms
class LoginForm(forms.Form):
email = forms.CharField()
password = forms.CharField()
# Create a view and make it accessible from the url.py:
# Create your views here.
from django.http import HttpResponse
from django.utils.html import escape
from django.shortcuts import render_to_response
from elearning.modules.login.loginform import LoginForm
from elearning.modules.models import Teacher
from django.http import HttpResponseRedirect
from django import http
#from django.core.exceptions import DoesNotExist
def gotoIndex(form):
return render_to_response('index.html', {'form': form})
def login(request):
r=HttpResponse()
loginform=LoginForm(request.POST)
if loginform.is_valid():
try:
#r.write("'"+str(loginform['email'])+"'")
login=Teacher.objects.get(email=loginform.data['email'])
#login=Teacher.objects.get(email="himu11@yahoo.com")
r.write(login.password)
# Check whether UserName and password mathc
except Teacher.DoesNotExist:
return gotoIndex(loginform)
if login.password !=loginform.data['password']:
return gotoIndex(loginform)
return HttpResponseRedirect('/modules/loginsuccess')
def loginsuccess(request):
return render_to_response('TeacherAdmin.html')
# Now write html:
#create a form
from django import newforms as forms
class LoginForm(forms.Form):
email = forms.CharField()
password = forms.CharField()
# Create a view and make it accessible from the url.py:
# Create your views here.
from django.http import HttpResponse
from django.utils.html import escape
from django.shortcuts import render_to_response
from elearning.modules.login.loginform import LoginForm
from elearning.modules.models import Teacher
from django.http import HttpResponseRedirect
from django import http
#from django.core.exceptions import DoesNotExist
def gotoIndex(form):
return render_to_response('index.html', {'form': form})
def login(request):
r=HttpResponse()
loginform=LoginForm(request.POST)
if loginform.is_valid():
try:
#r.write("'"+str(loginform['email'])+"'")
login=Teacher.objects.get(email=loginform.data['email'])
#login=Teacher.objects.get(email="himu11@yahoo.com")
r.write(login.password)
# Check whether UserName and password mathc
except Teacher.DoesNotExist:
return gotoIndex(loginform)
if login.password !=loginform.data['password']:
return gotoIndex(loginform)
return HttpResponseRedirect('/modules/loginsuccess')
def loginsuccess(request):
return render_to_response('TeacherAdmin.html')
# Now write html:
Sunday, December 2, 2007
django simplified
1. Download django trunk
2. Run:
#django_admin. py startproject projectname
# cd projectname
# python manage.py startapp appname
dont give too much though about project and app. At the the end of the they are just a python package
2. Run:
#django_admin. py startproject projectname
# cd projectname
# python manage.py startapp appname
dont give too much though about project and app. At the the end of the they are just a python package
Tuesday, October 9, 2007
apache-ssl 1.3 problem
mod_unique_id: unable to gethostbyname
In freebsd, edit /etc/hosts file with your hostname/IP entry,
like,
213.23.222.45 domain domain
In freebsd, edit /etc/hosts file with your hostname/IP entry,
like,
213.23.222.45 domain domain
Sunday, October 7, 2007
Freebsd java, ant
1. install diablo-caffe-freebsd6-i386-1.5.0_07-b01.tar.bz2
2. install apache-ant 1.7
2. install apache-ant 1.7
Monday, September 24, 2007
Subscribe to:
Posts (Atom)