Wednesday, April 18, 2012

Allow emulator to function well with smooth streaming, helps performance as well

When loading up playlist items.
item.MediaSource = new Uri(theholder, UriKind.RelativeOrAbsolute);
Leaving out or selecting just one seems to slow emulator and the actual phone perform by 50% or more.

Saturday, April 14, 2012

StoryBoard

public void FadeIn(UIElement target, double theseconds)
{
DoubleAnimation da = new DoubleAnimation();
da.From = 0;
da.To = 1.0;
da.Duration = TimeSpan.FromSeconds(theseconds);
da.AutoReverse = true;
//da.RepeatBehavior = RepeatBehavior.Forever;
da.RepeatBehavior = new RepeatBehavior(3);
DoubleAnimation csize = new DoubleAnimation();
csize.From = 150;
csize.To = 187;
csize.Duration = TimeSpan.FromSeconds(theseconds);
csize.AutoReverse = true;
csize.RepeatBehavior = new RepeatBehavior(3);
//da.RepeatBehavior = new System.Windows.Media.Animation.RepeatBehavior
//Storyboard.SetRepeatBehaviorProperty(da, new RepeatBehavior("4x"));
 
Storyboard.SetTargetProperty(da, new PropertyPath("Opacity"));
Storyboard.SetTarget(da, target);
Storyboard.SetTargetProperty(csize, new PropertyPath("Width"));
Storyboard.SetTarget(csize, target);
 
Storyboard sb = new Storyboard();
sb.Children.Add(da);
sb.Children.Add(csize);
 
 
if (mediaElement_C.CurrentState.ToString() == "Opening")
{
image5.Opacity = 1;
}
else
{
image5.Opacity = 0;
}
 
 
//clapping.Play();
//scoresound.Play();
sb.Begin();
}

StoryBoard

public void FadeIn(UIElement target, double theseconds)
{
DoubleAnimation da = new DoubleAnimation();
da.From = 0;
da.To = 1.0;
da.Duration = TimeSpan.FromSeconds(theseconds);
da.AutoReverse = true;
//da.RepeatBehavior = RepeatBehavior.Forever;
da.RepeatBehavior = new RepeatBehavior(3);
DoubleAnimation csize = new DoubleAnimation();
csize.From = 150;
csize.To = 187;
csize.Duration = TimeSpan.FromSeconds(theseconds);
csize.AutoReverse = true;
csize.RepeatBehavior = new RepeatBehavior(3);
//da.RepeatBehavior = new System.Windows.Media.Animation.RepeatBehavior
//Storyboard.SetRepeatBehaviorProperty(da, new RepeatBehavior("4x"));
 
Storyboard.SetTargetProperty(da, new PropertyPath("Opacity"));
Storyboard.SetTarget(da, target);
Storyboard.SetTargetProperty(csize, new PropertyPath("Width"));
Storyboard.SetTarget(csize, target);
 
Storyboard sb = new Storyboard();
sb.Children.Add(da);
sb.Children.Add(csize);
 
 
if (mediaElement_C.CurrentState.ToString() == "Opening")
{
image5.Opacity = 1;
}
else
{
image5.Opacity = 0;
}
 
 
//clapping.Play();
//scoresound.Play();
sb.Begin();
}

Wednesday, April 11, 2012

Read file from internet location and read through the lines

public partial class MainPage : PhoneApplicationPage
{
WebClient _webClient; // Used for downloading
}

public MainPage()
{
InitializeComponent();
_webClient = new WebClient();



_webClient.OpenWriteCompleted += (s1, e1) =>
{
//image1.Opacity = 1;
 
};

// when asyncread is completed this event is called

_webClient.OpenReadCompleted += (s1, e1) =>
{
if (e1.Error == null)
{
try
{
// parse out the forward slashes to give a nice beautiful aesthetic filename Nigel
fileName = txtURL.Text.Substring(txtURL.Text.LastIndexOf("/") + 1).Trim();
//
fileNameDisplay = fileName.Split('.'); // make it look better nigel
//textcode.Text = fileNameDisplay[0];
 
 
//txtUrl.Text.Substring(txtUrl.Text.LastIndexOf(“/”)+1).Trim();
bool isSpaceAvailable = IsSpaceIsAvailable(e1.Result.Length);
bool filenotpresent = FileNotPresent(fileName);
 
if ((isSpaceAvailable) && (filenotpresent))
// if they downloaded previously no need to download again
{
// Save mp3 to Isolated Storage
 
 
using (var isfs = new IsolatedStorageFileStream(fileName,
FileMode.CreateNew,
IsolatedStorageFile.GetUserStoreForApplication()))
{
long fileLen = e1.Result.Length;
byte[] b = new byte[fileLen];
e1.Result.Read(b, 0, b.Length);
isfs.Write(b, 0, b.Length);
isfs.Flush();
}
 
 
 
 
}
else
{
MessageBox.Show("Not enough to save space available to store file.");
}
textBlock33.Text = "Downloadfinished";
// playthesound();
readthefile(); // once we have dowloaded we can read the file see readtehfile below.
 
 
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
else
{
MessageBox.Show(e1.Error.Message);
}
};

}


private void Button_DownloadTextFile_Click(object sender, System.Windows.RoutedEventArgs e)
{ // if (_webClient.IsBusy)
{ // button already clicked and webclient still downloading, just state still downloading and bail NIGEL
textBlock33.Text = "Still Downloading..."; }
else {//examples
// txtURL.Text = "http://home.yourwebsiteprovicer.net/~yournameforexample/thefilename.txt"; txtURL.Text = "http://www.gutenberg.org/cache/epub/1400/pg1400.txt"; textBlock33.Text = "Downloading. . . ";
try {
_webClient.OpenReadAsync(new Uri(txtURL.Text.ToString()));
} catch
{ MessageBox.Show("problem occurred");
} textBlock33.Text = "Download Done Nigel"; }

}




void readthefile()
{
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile("nigel2.txt", FileMode.Open, FileAccess.Read))
{
//System.IO.Stream filestream = Application.GetResourceStream(new Uri("nigel2.txt", UriKind.Relative)).Stream;
using (StreamReader reader = new StreamReader(fileStream))
{ //Visualize the text data in a TextBlock text
// for (float soundtrip = .01f; soundtrip < 1f; soundtrip += .01f)
for (int nigelcounter = 0; nigelcounter < 4; nigelcounter += 1) // READ FIRST 4 LINES
{
theholder = reader.ReadLine();
textBlock33.Text += theholder;
}
// this.textBlock4.Text += reader.ReadLine();
}
fileStream.Close();
}

}

}

Sunday, April 1, 2012

Dynamically adjust panorama pages / items

PanoPage1.IsEnabled = false;
PanoPage1.Visibility = System.Windows.Visibility.Collapsed;


By doing this you can create a very dynamic application in panorma style.

For example if the user picks a genre or a certain item, then all panorama pages can be enabled just for that item, for example bands:

You select the band lankerspoon charlie,
and I enable all the panopages for lankerspoon, such as songs, about the band, band members, tour dates, other information.

next if user selects a different band, then I collapse and disable the lankerspoon and enable the next band, lets say it is Umphrey's Mcgee, or buckethead, oh yes!

In this way, each time an item is selected on the first pano page, you can enable other pages based on that, making an application that can contain a lot of data and use the limited screen size
in a very unique and desirable manner.

Nigel Dude out.