How to get video thumbnail of a video file in windows phone 8? - windows

I want to get thumbnail of a video file which uri or path is given. I have searched for api in windows phone developer site bt with no success. If anybody have does this please help me.

There is a method GetThumbnailAsync in class StorageFile which intended to retrieve thumbnail of image and video files. So despite the fact that MSDN states that this method throws exception and not supported for Windows Phone 8, actually this method works when invoked with parameter ThumbnailMode = ListView. But I seems that using this method requires ID_CAP_MEDIALIB_PHOTO_FULL.
var files = await KnownFolders.CameraRoll.GetFilesAsync(); // Throw UnauthorizedAccessException without ID_CAP_MEDIALIB_PHOTO_FULL
var storageFile = files.First();
var thumbnail = await storageFile.GetThumbnailAsync(ThumbnailMode.ListView);

Video Thumbnail code in c# windows phone
First we use capturesource.completed then after we create the thumbnail and use that thumbnail
and we use capturesource.Imageasync()
And this is the only way to generate the thumbnail image from video file.

Related

Image saved by the app doesn't show up in the gallery

I trying to create a whatsapp status saver in flutter. I trying to save the whatsapp status. I created a folder statuses in /storage/emulated/0/statuses/ and The process of copying goes well. But that Image is not shown in the gallery app.
So I even Tried storing it in DCIM/Camera still it doesn't show up there. But when the copy the same image using file explorer then that image shows up in gallery app. I think something is wrong with the image properties.
The code used to save is here.
saveFile(filePath) async {
String newFilename;
File originalFile = File(filePath);
Directory _directory = await getExternalStorageDirectory();
if (!Directory("/storage/emulated/0/statuses/").existsSync()) {
Directory("/storage/emulated/0/statuses/")
.createSync(recursive: false);
}
String curDate = DateTime.now().toString();
newFilename = "/storage/emulated/0/statuses/VIDEO-$curDate.jpg";
await originalFile.copy(newFilename).then((value) {
print("Saved: " + newFilename);
});
}
When you change a media, you should tell the device to re-scan. This image saver plugin will notify the Android OS about the media that is saved.
If you don't want the plugin, you can use platform channels to write native code yourself.
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
This issue is discussed here and here.

Opening a PDF file in Windows Phone

I'm developing an app for Windows Phone 7 and I'm using a Phonegap template for it.
Everything looks perfect, but now I’m stuck trying to open a PDF file in the browser.
I tried the following but that doesn’t work because the url of the PDF exceeds the 2048 character limit (it’s a data url). This code runs after the deviceReady event was fired.
var ref = window.open('http://www.google.com', '_blank', 'location=no');
ref.addEventListener('loadstart', function () { alert(event.url); });
Now, I'm trying to save the PDF file to storage and then I'm trying to have it opened by the browser, but the browser doesn't show anything. I'm editing the InAppBrowser.cs code from cordovalib and I added the following lines before calling browser.Navigate(loc);
private void ShowInAppBrowser(string url)
{
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
FileStream stream = store.OpenFile("test.pdf", FileMode.Create);
BinaryWriter writer = new BinaryWriter(stream);
var myvar = Base64Decode("the big data url");
writer.Write(myvar);
writer.Close();
if (store.FileExists("test.pdf")) // Check if file exists
{
Uri loc = new Uri("test.pdf", UriKind.Relative);
...
}
}
This code is returning the following error:
Log:"Error in error callback: InAppBrowser1921408518 = TypeError: Unable to get value of the property 'url': object is null or undefined"
I don’t wanna use ComponentOne.
Any help would be greatly appreciated!
You cannot open pdf files from the isolated storage in the default reader for PDF files. If the file is online e.g. it has a URI for it, you can use WebBrowserTask to open it since that will download and open the file in Adobe Reader.
On Windows Phone 8 you actually can open your own file in default file reader for that extension, but I am not sure how that will help you since you target PhoneGap and Windows Phone 7.
Toni is correct. You could go and try to build your own viewer (which would be the same thing as using C1, but with more time involved). I worked on a port of iTextSharp and PDFSharp for WP7, but neither of which are PDF Viewers. They are good for creating PDFs and parsing them some (but to render them there is more work involved). This has been a personal quest of mine, but honestly the best I have gotten is to be able to extract some images from the PDF (and none of the text)
try this
var installedLocation = Windows.ApplicationModel.Package.Current.InstalledLocation;
var assets = await installedLocation.GetFolderAsync("Assets");
var pdf = await assets.GetFileAsync("metro.pdf");
Windows.System.Launcher.LaunchFileAsync(pdf);
This worked correctly on my Device.

Windows Phone leave background music playing

My Windows Phone app was rejected because when I play a sound in the browser in my app it stops existing background music from playing (rejection issue 6.5.1).
How do I update my application to not stop background music?
My JavaScript is something like this:
var mySound = new Audio(soundpath);
Sound.play(mySound);
I could not find anything in Microsoft.Xna.Framework.Media that handles how the app handles browser sound, but maybe I missed something?
What you are looking for is from the xna soundeffect
Here is what I use and it works for me great for all my sound effects.
(You cannot use music with a 'soundeffect' object, as it will not pass the windows store qualifications. You have to use the MediaElement for music)
I can’t remember which you need but I have all these includes
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Media;
and this function
private static void LoadSoundEffect(string fileName, SoundEffectInstance mySound)
{
var stream = TitleContainer.OpenStream("Sounds/" + fileName);
var effect = SoundEffect.FromStream(stream);
FrameworkDispatcher.Update();
mySound = effect.CreateInstance();
}
If you use a SoundEffectInstance, you can start,pause,stop the soundeffect etc. without all the problems.
SoundEffect works as well, but I prefer the SoundEffectInstance.
Edit: If you use soundeffect, it will not effect the music being played.
I'm assuming that you are building a native Windows Phone app (.XAP) and then using a browser control to display your app content. If that is the case, you have checks that you will need to perform when the app is first opened. Below is a description of how to resolve that issue.
You will need to add this piece of code to your app (I suggest you check this every time your app loads/opens). Add a reference with the using statement as well for the Media.
if (Microsoft.Xna.Framework.Media.MediaPlayer.State == MediaState.Playing)
{
MessageBoxResult Choice;
Choice = MessageBox.Show("Media is currently playing, do you want to stop it?", "Stop Player", MessageBoxButton.OKCancel);
if (Choice == MessageBoxResult.OK)
mediaElement1.Play();
}
If the user allows or disallows the media to be played you must put checks in your JavaScript for this. You will fail certification again if the user says "Cancel" and you play music anyway.
There is more information on the topic here.

Play multiple audio streams in WP7 PhoneGap

I new to wp7 phonegap environment and I am having issues playing audio files. I am able to play one audio file as many times possible but cant play another audio of different instance, which is a requirement for my on-going project.
Any help?
you can use a phonegap native sound system
the javascript code for it is
src1="sounds/cartoon001.mp3"
src2="sounds/cartoon002.mp3"
var soundObj1 = new Media(src1,onSuccess,onError);
var soundObj2 = new Media(src2,onSuccess,onError);
soundObj1.play();
soundObj2.play();
also kindly check that mp3 files are supported in mobile.
you have to write a overriding functions for onSuccess and onnError.
javascript function to play:
playAudioFile("spellsound");
function playAudioFile(id){
var s=document.getElementById(id);
s.play();
}
html page<audio id='m' src='audio/baby/M.mp3'></audio>
or u can load src to audio tag by id in DOM

Is a .mp4 video file recorded in the WP Emulator ready for outside storage?

MS have released some code examples where a video is recorded in the WP Emulator and then saved in isolated storage. Is this .mp4 file ready to export away from the WP Emulator and play in other applications? Or is it needed to format it in some way or the other? If so, how to do it?
http://channel9.msdn.com/Shows/Inside+Windows+Phone/Inside-Windows-Phone-16-Mango-Camera-APIs
Source code for video recording is located in the WP project is called CameraUpload:
https://skydrive.live.com/?cid=bc58fec5c97e307a&sc=documents&id=BC58FEC5C97E307A%21295
http://msdn.microsoft.com/en-us/library/hh394041(v=vs.92).aspx
Edit:
I am trying to upload a video recorded in the WP Emulator to Azure blob.
A file does get uploaded, but I am not able to play that file in Zune.
I would like to be able to play the video file recorded in the WP Emulator on Zune, what to do to enable this?
The method in the Azure WCF service role, which saves the video looks like this:
(Please forgive if the method parameters have slightly misdirecting and confusing names.)
bool SaveImage(int salesItemId, string contentType, byte[] photo);
The video is saved to a blob container named "firstmay".
The code in the phone client saving the video looks like this:
client.SaveImageAsync(77, "mp4", GetPhotoBytes(m_capturedFileName));
public byte[] GetPhotoBytes(string fileName)
{
using (var appStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
IsolatedStorageFileStream isoStream = appStorage.OpenFile(m_capturedFileName, FileMode.Open);
byte[] buffer = new byte[isoStream.Length];
isoStream.Read(buffer, 0, (int)isoStream.Length); isoStream.Close();
return buffer;
}
}
When uploading a video from the WP client application, one first records a video and then uploads it by clicing "Save", it all goes on in the MainPage.
The client and server application can be downloaded from skydrive:
https://skydrive.live.com/redir?resid=159250F5CE7FE134!118
That'll all depend on what you want to be able to play back the content on. PCs with Zune would be fine, and I'd expect other video capable mobiles to be fine, but older mobiles, or standard Vista installs would require additional software, or transcoding of the video to be playable.

Resources