Display ProgressRing when the song is preparing and hide it when the song is playing - windows phone 8 - windows-phone-8

I developing application windows phone 8 that play song en streaming with MediaElement.
I want display ProgressRing when the song is preparing and hide it when the song is playing. I do this code below but doesn't show ProgressRing!!
progressRing.IsActive = true;
mediaElement.Source = new Uri(url, UriKind.Absolute);
mediaElement.Play();
progressRing.IsActive = false;

You need to yield control to the UI thread for the progress ring to be displayed. One convenient way to do that is to await Task.Delay (with a long enough delay to make sure the UI can refresh):
private async Task Play()
{
progressRing.IsActive = true;
await Task.Delay(15);
mediaElement.Source = new Uri(url, UriKind.Absolute);
mediaElement.Play();
progressRing.IsActive = false;
}
(note that you must make sure to mark your method as async)
An alternative way is to call Dispatcher.BeginInvoke (which seems counterintuitive seems you're already in the UI thread, but it works):
progressRing.IsActive = true;
Dispatcher.BeginInvoke(() =>
{
mediaElement.Source = new Uri(url, UriKind.Absolute);
mediaElement.Play();
progressRing.IsActive = false;
});

MediaElement.MediaOpened Event is fired when media loading has finished.
Try adding that event to the MediaElement and move the progressRing.IsActive statement to the EventHandler method.
mediaElement1.MediaOpened += new System.Windows.RoutedEventHandler(mediaElement1_MediaOpened);
progressRing.IsActive = true;
mediaElement1.Source = new Uri(url, UriKind.Absolute);
mediaElement1.Play();
private void mediaElement1_MediaOpened(object sender, RoutedEventArgs e)
{
progressRing.IsActive = false;
}

Related

AvalonDock: Keep floating windows visible when minimizing main application

Is it possibe to keep the floating windows visible when minimizing the main application?
Yes. the reason why it is being minimized is because the default owner of the floating window is the main window. so you have to set the floatingWindow.Owner = null; then you will also be able to put the main window in front of the floating window. if you want to switch between floating window and main window you can set floatingWindow.ShowInTaskbar = true;.
In my code i put it in a selectionChanged event handler so when i pop out a document it fires the selectionChanged event.
Document creation
private void userItem_Click(object sender, RoutedEventArgs e)
{
LayoutDocument ld = new LayoutDocument();
ld.Title = "All Users";
ld.ToolTip = "Manage all users";
//selection changed event
ld.IsSelectedChanged += Ld_IsSelectedChanged;
ld.IsActiveChanged += Ld_IsSelectedChanged;
Users users = new Users(ld);
ld.Content = users;
LayoutDocumentPane pane = ((todaysPayments.FindParent<LayoutDocumentPane>() ?? (panal.Children?[0] as LayoutDocumentPane)) ?? new LayoutDocumentPane());
pane.Children.Add(ld);
if (panal.ChildrenCount == 0)
{
panal.Children.Add(pane);
}
ld.IsSelected = true;
}
And the event handler
public void Ld_IsSelectedChanged(object sender, EventArgs e)
{
//get the floating windows from the DockingManager
manager.FloatingWindows.ToList().ForEach(floatingWindow =>
{
floatingWindow.Owner = null;
floatingWindow.ShowInTaskbar = true;
var fw = floatingWindow.Model as LayoutDocumentFloatingWindow;
floatingWindow.Title = fw?.RootDocument?.Title ?? "";
});
}

Close popup on hardwarebutton backpressed in windows phone 8.1 application

I have a popup that comes on a click event of button..
But I am unable to close the popup..I want to close popup on hardwarebutton_backpress event..
Can anyone plzz tell me how to do so..
I am using this code to show popup
Public void showpopup_click()
{
Popup p =new Popup();
p.child= new Mypopup();
p.Isopen=true;
}
Here Mypopup is my user control..
I am using visual studio and developing a windows phone 8.1 app..
Another approach, in my opinion better, is using the IsLightDismissEnabled property where you don't need to check whether a popup is already open or not, or if you have multiple open popups, everything is handled automatically.
var popup = new Popup();
popup.IsLightDismissEnabled = true;
popup.IsOpen = true;
You have to subscribe to the Windows.Phone.UI.Input.HardwareButtons.BackPressed event to handle the back button with custom logic. If you store the Popup in a field, you can easily set IsOpen property to false.
Like this:
private Popup _popup;
public void showpopup_click()
{
_popup = new Popup();
_popup.Child = new Mypopup();
_popup.IsOpen = true;
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
}
private void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs args)
{
_popup.IsOpen = false;
args.Handled = true;
Windows.Phone.UI.Input.HardwareButtons.BackPressed -= HardwareButtons_BackPressed;
}
In the event handler, you need to set the args.Handled property to true to prevent the application close on the back button pressed. You also need to unsubcrise from the event to avoid memory leak.

Animation using storyboard Windows phone 8

I am working on a Windows Phone 8 app. I am using a Storyboard to animate a series of images. It is working fine, but I want to call a particular method one second before the animation completes. I am using this code: Is there a way to do what I want?
var storyboard12 = new Storyboard
{
// RepeatBehavior = RepeatBehavior.Forever
};
var animation = new ObjectAnimationUsingKeyFrames();
Storyboard.SetTarget(animation, animationImage);
Storyboard.SetTargetProperty(animation, new PropertyPath("Source"));
storyboard12.Children.Add(animation);
for (int i = 1; i <=16; i++)
{
var keyframe = new DiscreteObjectKeyFrame
{
KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(300*i)),
Value = String.Format("/Images+Audio/images/animation images/2_Driving-a-car/Drive_background3 ({0}).png", i)
};
animation.KeyFrames.Add(keyframe);
}
DispatcherTimer timer11 = new DispatcherTimer();
timer11.Interval = TimeSpan.FromSeconds(4.1);
timer11.Tick += timer11_Tick;
timer11.Start();
storyboard12.Begin();
storyboard12.Completed += storyboard12_Completed;
}
void timer11_Tick(object sender, EventArgs e)
{
var timer = (DispatcherTimer)sender;
timer.Stop();
changeBackgroundImage3();
}
You can use an another Storyboard, that will change a background of your control. Such way is more appropriated by a performance reason. And DispatcherTimer Tick event won't be 100% fired after set interval, it could be fired later than 4.1, if it is important for you then it is the second reason to use a storyboard to change a background.

Force to refresh movie clip?

I have a really simple code piece like that;
loadingMc.visible = true;
trace("ok");
// send photo to server
loadingMc.visible = false;
Sending photo takes 3-5 seconds but movie clip becomes visible only for last second of process. I can see "ok" message in output at start of the process. So i assume problem is not redrawing movie clip. Is there any option to force redraw before process starts?
UPDATE:
Sending to server part;
upload.addEventListener(MouseEvent.CLICK, function(evt:MouseEvent):void{
loadingText.visible = true;
trace("ok");
var bmd:BitmapData = new BitmapData(1024,768,true,0);
bmd.draw(imageArea);
savePicToServer(bmd);
});
function savePicToServer(bmd:BitmapData):void
{
var jpgEncoder:JPGEncoder = new JPGEncoder(85);
var jpgStream:ByteArray = jpgEncoder.encode(bmd);
var loader:URLLoader = new URLLoader();
configureListeners(loader);
var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
var request:URLRequest = new URLRequest("http://localhost/test/upload.php?key=prvkey");
request.requestHeaders.push(header);
request.method = URLRequestMethod.POST;
request.data = jpgStream;
loader.load(request);
}
In the COMPLETE event;
loadingText.visible = false;
EDIT
Just from reading your code, I don't see why this should not be working - but FP does strange things sometimes.
In similar cases, I used setTimeout() to force the player to delay the subsequent actions and allow the screen to refresh:
upload.addEventListener(MouseEvent.CLICK, function(evt:MouseEvent):void{
loadingText.visible = true;
trace("ok");
setTimeout( doSave, 10 );
});
private function doSave() : void {
var bmd:BitmapData = new BitmapData(1024,768,true,0);
bmd.draw(imageArea);
savePicToServer(bmd);
}
If this still doesn't work, perhaps a longer timeout will do the trick - but 10ms usually should be enough to refresh the screen.
EDIT
Another way would be to add and remove an ENTER_FRAME listener to make sure the frame really was refreshed:
upload.addEventListener(MouseEvent.CLICK, function(evt:MouseEvent):void{
loadingText.visible = true;
trace("ok");
addEventListener( Event.ENTER_FRAME, onNextFrame );
});
private function onNextFrame( ev:Event ) : void {
removeEventListener( Event.ENTER_FRAME, onNextFrame );
doSave();
}
private function doSave() : void {
var bmd:BitmapData = new BitmapData(1024,768,true,0);
bmd.draw(imageArea);
savePicToServer(bmd);
}

onPeerConnect method using Adobe Cirrus does not get triggered

I have a NetGroup established using Adobe Cirrus. All clients can connect fine and see each other, since I receive NetGroup.Neighbor.Connect and NetGroup.MulticastStream.PublishNotify events when a new stream is being published.
However, if a user subscribes to a published stream, the publisher does not receive a notification (no NetStatusEvent and no callback to the onPeerConnect method). The subscriber receives the stream without problems, though.
All other questions about the non working onPeerConnect method were related to NetStream.DIRECT_CONNECTIONS, but in my case, I am using a NetGroup.
What is wrong here?
// Only the relevant parts, a few things have been stripped (e.g. connect the netGroup only when the NetConnection has been established etc.)
var groupSpecifier:GroupSpecifier = new GroupSpecifier("group");
groupSpecifier.multicastEnabled = true;
groupSpecifier.postingEnabled = true;
groupSpecifier.serverChannelEnabled = true;
groupSpecifier.objectReplicationEnabled = true;
groupSpecifier.ipMulticastMemberUpdatesEnabled = true;
groupSpecifier.routingEnabled = true;
var netGroup:NetGroup = new NetGroup(netConnection, groupSpecifier.groupspecWithAuthorizations());
var netStream:NetStream = new NetStream(netConnection, groupSpecifier.groupspecWithAuthorizations());
netStream.client = {onPeerConnect:onPeerConnect};
netStream.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
// Never gets called
public function onPeerConnect(netStream:NetStream):Boolean {
trace("onPeerConnect: "+netStream.farID);
return true;
}
private function onNetStatus(event:NetStatusEvent):void {
trace(event.info.code);
switch(event.info.code) {
case EventCodes.STREAM_CONNECT_SUCCESS :
netStream.attachCamera(camera);
netStream.attachAudio(microphone);
netStream.publish(streamName);
break;
}
}
onPeerConnect is only being called when using DIRECT_CONNECTIONS, not for NetGroups. Unfortunately, this is not mentioned in the documentation or anywhere else.