I am making an app which plays a Shoutcast stream but I cannot get the stream to play. I know the code works for other streams.
How do I get the Shoutcast stream to work?
Here's the code from the audio playback agent:
private void play(BackgroundAudioPlayer player)
{
if (player.Track == null)
{
player.Track = new AudioTrack(new Uri(streamURL, UriKind.Absolute), "Show", "Station", "", null);
}
player.Volume = 1;
if (player.PlayerState != PlayState.Playing)
{
player.Play();
}
}
see an example :
http://shoutcastmss.codeplex.com/
ShoutCasts are not very easy to stream .
Related
I am playing an audio via code as
playAudio(file_name: string) {
try {
const srcFile: string = `./assets/audio/${file_name}`
this.audio = new Audio(srcFile)
this.audio.load()
this.audio.play()
} catch (err) {
console.log(err.message)
}
}
when I call this method, IDM gives file to download as in figure
What can be possible solution to prevent IDM or any other downloader from doing this
I have a spec in which there is a need to ignore HTTPS certificates and also to get the status of Upload/Download.
I am using HttpClient to ignore the certificate but i could not find the way to get the status of downloading/Uploading.
I know it was there in WebClient Windows Phone 8 and Webclient not there in Windows 8.1.
So please guide me to accomplish both these things.
For Download progress, You can return response stream from your Http request and can use below code to write to file which also display progress status
IInputStream inputStream = null;
IRandomAccessStream fs = null;
try
{
inputStream = responseStream.AsInputStream();
ulong totalBytesRead = 0;
fs = await file.OpenAsync(FileAccessMode.ReadWrite);
ulong fileSize = Convert.ToUInt64(Size);
while (true)
{
// Read from the web.
if (!cancellationToken.IsCancellationRequested)
{
IBuffer buffer = new Windows.Storage.Streams.Buffer(512);
buffer = await inputStream.ReadAsync(
buffer,
buffer.Capacity,
InputStreamOptions.None);
if (buffer.Length == 0)
{
// There is nothing else to read.
break;
}
// Report progress.
totalBytesRead += buffer.Length;
double progress = ((double)totalBytesRead / fileSize);
double Value = progress * 100;
System.Diagnostics.Debug.WriteLine("Bytes read: {0}", totalBytesRead);
await fs.WriteAsync(buffer);
}
else
{
inputStream.Dispose();
fs.Dispose();
await file.DeleteAsync();
break;
}
}
inputStream.Dispose();
fs.Dispose();
}
catch
{
}
For upload Progress, there is no in built support to do that, but you can use
ProgressMessageHandler found in System.Net.Http.Handler which you can found on Nuget and than hook that to your HttpClient Object.
I have an wp8 app using PeriodicTask background Agent.
The task update the information of multiple live tiles,
using POST Client to get title and image url from my server to update the live tile.
Background agent works just fine in debugging and releasing mode. When the .xap file was deployed into my device using XAPDeployement tool, the background Agent also works perfectly.
However, it won't work after submitted to wp app store, no matter it's beta version or not.
If the app is downloaded from store, the background agent has never worked, and it is blocked by system after a few minutes.
How come it goes wrong since the XAP files are the same?
part of code:
public static Task<string> jsonPostClientTask(Dictionary<string, object> parameters, string url)
{
var results = new TaskCompletionSource<string>();
PostClient proxy = new PostClient(parameters);
try
{
proxy.DownloadStringCompleted += (sender, e) =>
{
if (e.Error == null)
{
string response = e.Result.ToString();
results.TrySetResult(response);
}
else
{
results.TrySetResult("");
results.TrySetException(e.Error);
}
};
proxy.DownloadStringAsync(new Uri(url));
}
catch
{
results.TrySetResult("");
}
return results.Task;
}
ScheduledAgent class:
protected override void OnInvoke(ScheduledTask task)
{
foreach (var tile in tileList)
{
string dataString = jsonPostClientTask(parameters, url);
//update tile in used
FlipTileData tileData = new FlipTileData()
{
BackContent = "string content",
WideBackContent = "string back content",
BackBackgroundImage = new Uri("http://xxxx.xxx/xxx.png", UriKind.RelativeOrAbsolute),
WideBackBackgroundImage = new Uri("http://xxxx.xxx/xxx.png", UriKind.RelativeOrAbsolute),
};
ShellTile primaryTile = ShellTile.ActiveTiles.First();
if (primaryTile != null)
primaryTile.Update(tileData);
}
}
i have used this code to get camera access how i can load it on page load
private function startVideo():void
{
if (true) // TODO: Recognize no video settings
{
var camera:Camera = Camera.getCamera(cameraIndex.toString());
if (camera)
{
vidMe.attachCamera(camera);
if (outgoingStream)
{
outgoingStream.attachCamera(camera);
}
}
}
else
{
vidMe.attachCamera(null);
if (outgoingStream)
{
outgoingStream.attachCamera(null);
}
}
}
Flash shows the camera request dialog the first time you call attachCamera(). To have a user be asked upfront, before your flash application reaches any functionality, I would suggest adding it upfront in our constructor.
This dummy function puts together a fake NetConnection, and connects it to no server. Going through this upfront will present a user with the camera use dialog while your flash application is loading, thus happening on page refresh or initial load.
private function ensurePermissions() : void {
var unusedNetConnection : NetConnection = new NetConnection()
unusedNetConnection.connect( null );
var ensureCamPermissions : NetStream = new NetStream( unusedNetConnection );
ensureCamPermissions.attachCamera( myCamera );
try {
ensureCamPermissions.close();
unusedNetConnection.close();
} catch( error:Error ) {
// Ignore any errors here
} finally {
ensureCamPermissions = null;
unusedNetConnection = null;
}
}
I'm using the official Adobe Facebook API in my Flash/AS3 application and for some reason the call the /me/picture seems to fail whereas the the call the /me/friends seems to work just fine:
This works OK:
Facebook.api('/me/friends', onFriendsLoaded );
protected function onFriendsLoaded( response:Object, fail:Object ) : void
{
// I can get the friends from the response object
}
This fails:
Facebook.api('/me/picture', onPictureLoaded );
protected function onPictureLoaded( response:Object, fail:Object ) : void
{
// Here response is null and fail is ÿØÿà
}
I'm calling both methods right after each other. What could be the problem?
The /me/picture call is actually not an api call at all. http://graph.facebook.com/me/picture is the url of the photo. You can actually set an image to that url. I am not an expert in Flash, but if you were doing this in html you would do the following:
<img src="http://graph.facebook.com/facebook_id/picture" />
This would show the users picture. Additionally, if you wanted to download the picture's bytes you would just make a normal web request. The response stream would be the image file.
Try this way
function onPictureLoaded(response:Object,fail:Object):void{
if (fail)
{
trace("Error");
}
var friends = response as Array;
var l:int = friends.length;
for (var i:int=0; i < l; i++)
{
trace("http://graph.facebook.com/" + friends[i].id + "/picture/")
}
}