Hi,
I'm having a bit of a problem with viewing a streaming video - as
always, the http site points to somewhere else that does the actual
streaming. When I pass the code into the viewer, it just gives me the
android video server error 100 (which is a state issue).
Do I need to do anything special to set the source as something other
than the http that does the redirect?
My code looks like this
using System;
using System.Security.Cryptography;
using System.Text;
using Android.App;
using Android.Media;
using Android.OS;
using Android.Views;
using Android.Widget;
namespace oqhra_android
{
[Activity(Theme = "@android:style/Theme.NoTitleBar")]
public class videoplayer : Activity, ISurfaceHolderCallback
{
private MediaPlayer mp;
private string url;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.video);
url = base.Intent.GetStringExtra("url");
int x = base.Intent.GetIntExtra("xSize", 300);
int y = base.Intent.GetIntExtra("ySize", 500);
string urlHost =
"http://replays.robertsstream.com/racereplays/replaysmobile.php?";
//urlHost =
"rtsp://66.209.93.10:554/2012/_definst_/300/mp4:" + url + "_300.mp4?";
<- redirects to here
string pk = "oq56rfju4vnjkm789grt";
DateTime d1 = new DateTime(1970, 1, 1);
DateTime d2 = DateTime.UtcNow;
TimeSpan ts = new TimeSpan(d2.Ticks - d1.Ticks);
double sd = ts.TotalMilliseconds;
string UTC = sd.ToString().Substring(0, 10);
string MD5String = UTC + pk + url;
MD5String = GetMD5Hash(MD5String);
urlHost += "race=" + url;
urlHost += "&cust=OQHRA";
urlHost += "&t=" + UTC;
urlHost += "&h=" + MD5String;
url = urlHost;
if (mp != null)
{
mp.Reset();
mp.Release();
}
mp = new Android.Media.MediaPlayer();
var surface = FindViewById<SurfaceView>(Resource.Id.surfaceView);
var holder = surface.Holder;
holder.AddCallback(this);
holder.SetType(Android.Views.SurfaceType.PushBuffers);
holder.SetFixedSize(x - 50, y - 75);
#if DEBUG
Console.WriteLine("videoplayer - url = {0}, x - 50 = {1},
y - 75 = {2}, mp.Info = {3}", url, x - 50, y - 75, mp);
#endif
Button btnClose = FindViewById<Button>(Resource.Id.btnClose);
btnClose.Click += (object s, EventArgs e) => { this.Finish(); };
}
public void SurfaceDestroyed(ISurfaceHolder holder)
{
mp.Release();
}
public void SurfaceChanged(ISurfaceHolder holder,
Android.Graphics.Format a, int b, int c)
{ }
public void SurfaceCreated(ISurfaceHolder holder)
{
try
{
mp.SetDisplay(holder);
mp.SetDataSource(url);
mp.Prepared += new EventHandler(startPlayer);
mp.PrepareAsync();
}
catch (Java.Lang.IllegalStateException e)
{
Toast.MakeText(this, e.ToString(), ToastLength.Long).Show();
}
catch (System.Exception e)
{
Toast.MakeText(this, e.ToString(), ToastLength.Long).Show();
}
}
public void startPlayer(object s, EventArgs e)
{
mp.Start();
}
public static string GetMD5Hash(string input)
{
System.Security.Cryptography.MD5CryptoServiceProvider x =
new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] bs = System.Text.Encoding.UTF8.GetBytes(input);
bs = x.ComputeHash(bs);
System.Text.StringBuilder s = new System.Text.StringBuilder();
foreach (byte b in bs)
{
s.Append(b.ToString("x2").ToLower());
}
return s.ToString();
}
}
}
The above works fine if you go to mobile.oqhra.com, click on videos,
remmington park and then any race and the code is a direct copy and
paste from the iPhone source (for the encryption). The video player
code is from Wally's amazing Monodroid book - so that will work!
Is there anything that has to be done for the redirect and also, how
do I catch the server error?
Paul
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid