How convert a "media.library.song" to "mediaElement" please.. - Windows Phone 7 Development and Hacking

Hello it was some days I encounter a difficulty to play music that is in the internal memory of the mobile phone.
I want to play music that is in phone memory with a "MediaElement"and not with the "MediaPlayer.play ()".
Here's my example:
Code:
foreach( var source in mediaSource.GetAvailableMediaSource())
{
mediaelement test= new mediaelement();
ml =new MediaLibrary(source);
mediaelement test = ml.songs[1]; // !!!! Erreur ici!!!
}
Is it possible to convert a "media.library.song [0] " to "MediaElement"?
please help me I'm losing hope ^ ^
In any case I find it unfortunate that we can not access the music from the phone without having to go through the application of basic phone

up please ...

kingmiddle said:
Hello it was some days I encounter a difficulty to play music that is in the internal memory of the mobile phone.
I want to play music that is in phone memory with a "MediaElement"and not with the "MediaPlayer.play ()".
Here's my example:
Code:
foreach( var source in mediaSource.GetAvailableMediaSource())
{
mediaelement test= new mediaelement();
ml =new MediaLibrary(source);
mediaelement test = ml.songs[1]; // !!!! Erreur ici!!!
}
Is it possible to convert a "media.library.song [0] " to "MediaElement"?
please help me I'm losing hope ^ ^
In any case I find it unfortunate that we can not access the music from the phone without having to go through the application of basic phone
Click to expand...
Click to collapse
drop mediaelement control to your layout , rename it to ml , and it should works
Tom

Thank you very much for your response! I'm glad to see that there may be a solution.
However I have a question for "xm" you advise me ..
Do I have to rename my MediaElement in the file format "XM"?
Is that correct?

thank you very much, I realized my mistake.
But do I convert a music "Medialibrary" to "MediaElement?

Oh damn... MediaElement != Song
You must use MediaPlayer.Play(Song song);

Yess i say ^^ but i need use a mediaElement to read a music from "mediaLibrary"
it's possible ?
Because the "mediaPlayer" from windows phone can't set position (seek position) of the song ... :-(
Thanky you for your futur's responses..

Related

play raw audio on char device

idlike to do something like:
cat /system/media/audio/ui/Forest.ogg > /dev/snd/pcmC0D0p
but isnt working, do you have any clue?
husq510 said:
cat /system/media/audio/ui/Forest.ogg > /dev/snd/pcmC1D0c
Click to expand...
Click to collapse
hm, this doesn't work on my linux box either but
Code:
cat xyz.ogg > /dev/dsp
does ... as ogg is not raw audio it's just noise.
sadly there is no /dev/dsp on android. if i may ask, what do you want to do? you could write a simple c program to play a raw file, would not be a lot of work i guess ...
probably mediaserver is locking filedescriptor.. therwise it would be possible to do:
cat file.au > /dev/snd/pcmC0D0p
Id like to play sound when some event occur, w/o write anything.
husq510 said:
probably mediaserver is locking filedescriptor.. therwise it would be possible to do:
cat file.au > /dev/snd/pcmC0D0p
Id like to play sound when some event occur, w/o write anything.
Click to expand...
Click to collapse
hm, i understand...can't help you there.
playing music files from within an android app is just several lines of code tho.
code snippet from a program i am currently working on:
Code:
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.reset();
try {
mediaPlayer.setDataSource("/system/media/audio/ui/Forest.ogg");
mediaPlayer.prepare();
} catch (IOException e) { /* ... */ }
mediaPlayer.start();

Open ZIP file in Silverlight

Hi,
I'm working on my first application for Windows Phone. I got a ZIP file which contains a huge amount of XML files and which has to be
updated through the app. So I declared the 'Build Action' of the file to 'Content'. Now I'm stuck opening the file for reading and extracting
a stream for a specific XML file.
I tried File.OpenRead but Visual Studio Express crashes when trying to debug this.
Do I need to use Application.GetResourceStream? If yes, can someone post a working example with a content ZIP file (not resource).
Can anyone help me?
Thank you,
toolsche
Try http://senssoft.com/ZipTest.zip
I've created that example project for Freda's developer.
Hi,
Unfortunately that doesn't help me.
1) U did set the file as "Resource" => it will not be updateable because it's within the assembly. If I'm wrong, please tell me...
2) U used an external library (SharpZipLib) which I hope it wouldn't be necessary.
1) I've used an embedded file (actually, epub == zip) to simplify the solution. It's just an example. U may copy the resource file to IsolatedStorageFile / download it from web/ whatever you want. I can't teach you how to use Silverlight for WP7 - buy some good book...
2) SharpZipLib IS NECESSARY! Other "zippers" looks like not a 100% compatible with WinZip/linux zippers (see Freda corresponding topic). SharpZipLib did the job very well.
Of course it up to you: what you want to use. But I gave you a 100% working and tested solution.
Hi,
I'm not in doubt that your solution is working and I thank you for your suggestion.
Maybe I'm on the wrong path, but what I think I need is a solution for opening
a zip file that is NOT part of the assembly (which I think it is if you declare it as
embedded resource).
My intention is to load one or more zip files from a server which the application
should be able parse/remove/replace if outdated. I tried to find a solution but had
no luck so far. MSDN has an example but I couldn't get it to work because I don't
know where the zip file should be located:
http://msdn.microsoft.com/en-us/library/cc190632(v=VS.95).aspx
Try to use IsolatedStorageFile and WebClient, something like this:
Code:
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
WebClient downloader = new WebClient();
downloader.OpenReadCompleted += delegate(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error == null)
{
using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream("myfile.zip", FileMode.Create, isf))
{
Byte[] buffer = new Byte[e.Result.Length];
e.Result.Read(buffer, 0, buffer.Length);
stream.Write(buffer, 0, buffer.Length);
}
DoSomethingWithZip("myfile.zip");
}
};
downloader.OpenReadAsync(new Uri("http://mysite.com/archive.zip", null));
Thank you for the quick answer. I will try it as soon as possible and post the results.
EDIT: Thanks, it's working as suggested.

[Q][SOLVED] PhotoChooserTask Mango Exception

A simple photochooser task application throws a Nullrefference exception(Invalid pointer) and pixel height and width is 0 on mango, on nodo it worked alright.
Am I missing a cast? or this is a bug in mango, and will be fixed?
Here's the code:
Code:
private PhotoChooserTask photo;
// Constructor
public MainPage()
{
InitializeComponent();
photo = new PhotoChooserTask();
photo.Completed += new EventHandler<PhotoResult>(photo_Completed);
}
void photo_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
BitmapImage bi = new BitmapImage();
bi.SetSource(e.ChosenPhoto);
//////////////////////////////////////////////////////////////////////////////////////
var wb = new WriteableBitmap(bi);//Exception here
/////////////////////////////////////////////////////////////////////////////////////
// bi.PixelHeight and bi.PixelWidth == 0;
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
photo.Show();
}
}
Hope someone can help.
Thanks in advance
This is because you need to set the CreateOptions property of the BitmapImage before you use it to construct the WriteableBitmap.
The default 'create' option on WP7 is DelayCreation (it may be BackgroundCreation in some of the 7.1 betas, but the mango RTM I think is DelayCreation) but either way the problem you're having is that your image has not been initialised yet at the point you use it in the WriteableBitmap's constructor (hence the null reference exception).
The options (depending what you set) let images be only initialised when needed, and downloaded on separate threads / asynchronously, which can help performance (or at least stop the phone blocking other things happening whilst images are loaded). Users also have the ability with the photo chooser to pick images from online ablums, so as you can imagine you also have to handle perhaps a second or two waiting for a download to complete, and of course downloads can also fail when connections drop etc. which you can handle too.
So in answer to your question (off the top of my head, not confirmed it with code) set the createoptions to none, and use the Bitmap's ImageOpened event to construct the WritableBitmap (you may also want to handle the Bitmap's ImageFailed event). Make sure you set up the ImageOpened event before you set the source, i.e.
BitmapImage bi = new BitmapImage();
bi.CreateOptions = BitmapCreateOptions.None;
bi.ImageOpened += new (some event name)
bi.ImageFailed += new (some event name)
bi.SetSource(e.ChosenPhoto);
Hope that helps,
Ian
Thank you very much
Problem solved
otherworld said:
This is because you need to set the CreateOptions property of the BitmapImage before you use it to construct the WriteableBitmap.
The default 'create' option on WP7 is DelayCreation (it may be BackgroundCreation in some of the 7.1 betas, but the mango RTM I think is DelayCreation) but either way the problem you're having is that your image has not been initialised yet at the point you use it in the WriteableBitmap's constructor (hence the null reference exception).
The options (depending what you set) let images be only initialised when needed, and downloaded on separate threads / asynchronously, which can help performance (or at least stop the phone blocking other things happening whilst images are loaded). Users also have the ability with the photo chooser to pick images from online ablums, so as you can imagine you also have to handle perhaps a second or two waiting for a download to complete, and of course downloads can also fail when connections drop etc. which you can handle too.
So in answer to your question (off the top of my head, not confirmed it with code) set the createoptions to none, and use the Bitmap's ImageOpened event to construct the WritableBitmap (you may also want to handle the Bitmap's ImageFailed event). Make sure you set up the ImageOpened event before you set the source, i.e.
BitmapImage bi = new BitmapImage();
bi.CreateOptions = BitmapCreateOptions.None;
bi.ImageOpened += new (some event name)
bi.ImageFailed += new (some event name)
bi.SetSource(e.ChosenPhoto);
Hope that helps,
Ian
Click to expand...
Click to collapse
Hello, I have the same problem (NullReferenceException) and have read you response, which from what I see it is the solution, but I have a problem; not where I have to go to do I change them that you propose. I would be so kind of explaining to me that I have to continue steps. It English me is very bad and I am using a translator.
I have HTC Trophy the v.th 7740.16 with chevrom and U2M7740 of Ansar.
Thank you in advance and greetings.
Hi,
If you upload your code / project I will take a look and see where the error is.
Si me muestras su código / proyecto, puedo ver por qué recibiras una excepción NullReference
Ian
otherworld said:
Hi,
If you upload your code / project I will take a look and see where the error is.
Si me muestras su código / proyecto, puedo ver por qué recibiras una excepción NullReference
Ian
Click to expand...
Click to collapse
Hello,
The question is that it is not any project, applications do not develop (although I would like). This type of errorr (nullreferenceexception) happens to me since I updated to Mango, so much in v.7720.68 as in v.7740.16 and happens in apps as Morfo, Fantasy Painter, and at the time of choosing fund in Touchxperience. Not if these apps are not conditioned to Mango or if, perhaps, from the record it might change some type of configuration or entering the Xaml of the app to be able to change some fact, end not...
For the little that, an error of the photochooser seems to be, the question is if it is possible to gain access to him and as doing it.
Anyhow thank you very much and a cordial greeting.
Hi,
If it is not a code issue then I do not know what it could be. Are you using a custom rom?
Good luck with it.
Ian
otherworld said:
Hi,
If it is not a code issue then I do not know what it could be. Are you using a custom rom?
Good luck with it.
Ian
Click to expand...
Click to collapse
Hello. Not, I am with official Mango the v.th 7740.16. I have already restored to factory and it continues the error. I believe that it is a question of the update, it must have a mistake in the pitcher of photos or some error with the librerie, do not know...
Thank you anyhow and greetings.
Hello, otherworld.
I continue with the same problem, 'nullreferenceexception' related with 'chooserphoto' in some application. The curious thing is that someone of them me work correctly, I gain access to me librery and it takes the photos, and in others not, as for example Morfo. I do not know if the problem is in the code source of these applications or phone is in me. Is this the code source of Morfo, is it possible to correct so that this does not happen?
Thank you in advance and greetings.

ISETool.exe bug

Today I found very annoying and strange bug (or, may be, MS call it "feature" ). Seems like directories on isf can hold 1024 files only...
Try code below:
Code:
Random rnd = new Random();
using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
{
byte[] data = new byte[1024];
isf.CreateDirectory("test");
for (int i=0; i<1025; i++)
{
string fileName = "test\\" + i.ToString("D4") + ".bin";
using (IsolatedStorageFileStream fs = new IsolatedStorageFileStream(fileName, FileMode.Create, isf))
{
rnd.NextBytes(data);
fs.Write(data, 0, data.Length);
}
}
}
After loop completed, resulting directory "test" will be empty! But change i<1024 and you'll get all yours 1024 files...
Tested on emulator and HTC Surround, same results. Can't find any documentation about this limitation... Shame on you, MS!
Update: another strange behavior ('cause of this bug) - if you already have 1024 files and try to add one more, the whole directory content is "magically" disappear But exception isn't thrown...
Interesting, I'll try it as well. This would be lame to have to work around.
Dbeattie said:
Interesting, I'll try it as well.
Click to expand...
Click to collapse
Yes, please, confirm...
I can't test this at the moment but I know I write well over 1000 files to /shared/media so I'm curious to tet this.
sensboston said:
Yes, please, confirm...
Click to expand...
Click to collapse
Hey just tried it out, wrote 2k items to a folder called "Data".
While it didn't show up in the Windows Phone Power tools, the file does exist in the folder itself.
bool success = storage.FileExists(Path.Combine("data", "1999"));
So it's either a problem with the WPConnect api or with the power tools, haven't tried the command line tool.
Yep, fortunately you are right, it's a ISETool.exe (or drivers) bug, not a WP7 ISF.
sensboston said:
Yep, fortunately you are right, it's a ISETool.exe (or drivers) bug, not a WP7 ISF.
Click to expand...
Click to collapse
Could you therefore edit the title of the thread please?
Thanks.

[dev] hook into PhoneStatusBarPolicy

Hello alltogether,
I digged into the Lollipop code to look for a solution to restore the old Kitkat silent mode in Lollipop with Xposed.
I got a working prototype now but would like to add the silentmode icon back to the statusbar.
Unfortunately it got removed in Lollipop so I have to port it forward from an older ROM.
To do that I need to hook into the PhoneStatusBarPolicy class, which for some reason fails.
This is my code:
Code:
private static final String CLASS_PHONE_STATUSBAR_POLICY = "com.android.systemui.statusbar.phone.PhoneStatusBarPolicy$1";
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
if (lpparam.packageName != "android")
return;
final Class<?> classStatusbarPolicy = XposedHelpers.findClass(CLASS_PHONE_STATUSBAR_POLICY, lpparam.classLoader);
XposedHelpers.findAndHookMethod(classStatusbarPolicy, "updateVolumeZen",
new XC_MethodReplacement() {
...
});
}
}
But for some reason it fails:
Code:
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.android.systemui.statusbar.phone.PhoneStatusBarPolicy" on path: DexPathList[[zip file "/system/framework/services.jar", zip file "/system/framework/ethernet-service.jar", zip file "/system/framework/wifi-service.jar"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
Does anyone have an idea?
Thanks!
You should change lpparam.packageName != "android"
to
lpparam.packageName.equals("android")
Why android? This class is within com.android.systemui package.
C3C076 said:
Why android? This class is within com.android.systemui package.
Click to expand...
Click to collapse
Ah I guess I misread rovos post about the new API with the dummy android package.
In detail, this means: If you want to hook a system service like PackageManagerService, you can no longer do that in initZygote(). Instead, move your code to handleLoadPackage() and check for dummy package "android". Make sure you use lpparam.classLoaders when looking for classes and hooking methods. This way has worked in older Android versions as well, so you don't lose backwards-compatiblity.
Click to expand...
Click to collapse
After reading it again this just applies to system services. And based on some code I saw at your Gravitybox repo it doesn't even seem to apply to all system services as you are still hooking a couple during initZygote
Xposed is new to me, but it's an amazing toolset!
So hooking works fine now, unfortunately it just got a bit ugly as the StatusBarManager which I'd like to use for the icons can't get imported. I guess I'll have to use some reflection to get into the class hehe.

Categories

Resources