xmlns:VideoStream="using:Microsoft.PlayerFramework"
VideoStream:MediaPlayer Source="http://155.41.145.37/mjpg/video.mjpg"
Worked fine when i change the Source pointed to .mp4 file. When changing to .mjpg it won't work. When running it shows the error " This video is failed to play".
Please help
Vishnu Aravind
This works:
Doc: https://channel9.msdn.com/coding4fun/articles/MJPEG-Decoder
Download:
http://mjpeg.codeplex.com/
Sample code:
MjpegDecoder _mjpeg;
public MainPage()
{
this.InitializeComponent();
_mjpeg = new MjpegDecoder();
_mjpeg.FrameReady += mjpeg_FrameReady;
_mjpeg.ParseStream(new Uri("http://155.41.145.37/mjpg/video.mjpg"));
}
private async void mjpeg_FrameReady(object sender, FrameReadyEventArgs e)
{
// Convert IBuffer to IRandomAccessStream.
var ras = new InMemoryRandomAccessStream();
await ras.WriteAsync(e.FrameBuffer);
ras.Seek(0);
// Show image.
var bitmap = new BitmapImage();
await bitmap.SetSourceAsync(ras);
image.Source = bitmap;
}
Related
i want to just convert youtube links to MP3 file in asp.net.I have research about that and do the code but the code gives exception like below:
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. how to resolve that
protected void Button1_Click(object sender, EventArgs e)
{
try
{
string url = TextBox1.Text;
var source = #"C:\Users\Dipak";
var youtube = YouTube.Default;
var vid = youtube.GetVideo(url);
File.WriteAllBytes(source + vid.FullName, vid.GetBytes());
var inputFile = new MediaFile { Filename = source + vid.FullName };
var outputFile = new MediaFile { Filename = $"{source + vid.FullName}.mp3" };
using (var engine = new Engine())
{
engine.GetMetadata(inputFile);
engine.Convert(inputFile, outputFile);
}
}
catch (Exception exception)
{
}
}
I have found this types of code in Stack overflow but won't work
This is my code for recording sound in temporary file. when i record sound and then listen to playback, everything goes well, but when i click again on playback button, i get this error:
How can i solve this problem?
Code:
using System.Collections.Generic;
using System.IO;
using System.IO.IsolatedStorage;
using System.Windows;
using System.Windows.Controls;
using Coding4Fun.Toolkit.Audio;
using Coding4Fun.Toolkit.Audio.Helpers;
namespace AudioRecorder.UserControls
{
public partial class SoundRecorderPanel : UserControl
{
private MicrophoneRecorder _recorder = new MicrophoneRecorder();
private List<IsolatedStorageFileStream> _audioList = new List<IsolatedStorageFileStream>();
private int _counter;
public SoundRecorderPanel()
{
InitializeComponent();
}
private void ButtonRecord_OnChecked(object sender, RoutedEventArgs e)
{
_recorder.Start();
}
private void ButtonRecord_OnUnchecked(object sender, RoutedEventArgs e)
{
_recorder.Stop();
SaveTempAudio(_recorder.Buffer);
}
private void SaveTempAudio(MemoryStream buffer)
{
if (_counter==2)
return;
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
var bytes = buffer.GetWavAsByteArray(_recorder.SampleRate);
var tempFileName = "tempwaveFile_"+_counter;
IsolatedStorageFileStream audioStream = isoStore.CreateFile(tempFileName);
audioStream.Write(bytes,0,bytes.Length);
_audioList.Add(audioStream);
_counter++;
}
}
private void ButtonPlayBack_OnClick(object sender, RoutedEventArgs e)
{
var index = int.Parse(((Button) sender).Tag.ToString());
var audioPlayer = new MediaElement {AutoPlay = true};
if (index < _audioList.Count)
{
audioPlayer.SetSource(_audioList[index]);
LayoutRoot.Children.Add(audioPlayer);
audioPlayer.Play();
}
}
}
}
You can 100% use a using block. Issue was how you were attempting to access the stream in the separate event. Reopen it rather than attempt to save a reference in an index to the stream.
using (var stream = new IsolatedStorageFileStream(_fileName, FileMode.Open, storageFolder))
{
playBack.SetSource(stream);
playBack.Play();
}
Use the sample code:
https://coding4fun.codeplex.com/SourceControl/latest#source/Coding4Fun.Toolkit.Test.WindowsPhone.Common/Samples/Audio.xaml.cs
I solved my problem , it's weird but it seems using(){} does not work ! and i disposed IsolatedStorageFile and IsolatedStorageFileStream manually . and also i changed the code under ButtonPlayBack click event . this is my new code for someone who has a same problem .
private void SaveTempAudio(MemoryStream buffer)
{
if (_counter == 2)
return;
var isoStore = IsolatedStorageFile.GetUserStoreForApplication();
var bytes = buffer.GetWavAsByteArray(_recorder.SampleRate);
var tempFileName = "tempwave_" + _counter;
var audioStream = isoStore.CreateFile(tempFileName);
audioStream.Write(bytes, 0, bytes.Length);
_audioList.Add(audioStream);
_counter++;
isoStore.Dispose();
audioStream.Close();
audioStream.Dispose();
}
private void ButtonPlayBack_OnClick(object sender, RoutedEventArgs e)
{
var index = int.Parse(((Button) sender).Tag.ToString());
var fileName = "tempwave_" + ((Button) sender).Tag;
if (index >= _audioList.Count)
return;
var isoStorage = IsolatedStorageFile.GetUserStoreForApplication();
var fileStream = isoStorage.OpenFile(fileName, FileMode.Open, FileAccess.Read);
SoundPlayer.SetSource(fileStream);
SoundPlayer.Play();
isoStorage.Dispose();
fileStream.Close();
fileStream.Dispose();
}
Im using a MediaStreamSource to use the camera... everything works, except when I try to capture the image!
I think the problem is the object MediaStreamSource
public class CameraStreamSourceModel : MediaStreamSource
{
private MemoryStream _cameraStream = null; // here I've the stream from camera
...
public async void CapturePhoto()
{
// Save the image as a jpeg to the camera roll
MediaLibrary library = new MediaLibrary();
string filename = AppResources.ApplicationTitle + "_" + DateTime.Now.ToString("G");
Picture pic = library.SavePicture(filename, _cameraStream); //Here I've the exception
}
}
The exception is
System.InvalidOperationException: An unexpected error has occurred.
I've enabled ID_CAP_MEDIALIB_PHOTO.
I am sure the code to save image works because i can save static stream in media library, but not stream from camera!
Can anyone help me? Thank you
You could simply use a camera_capture_task
CameraCaptureTask cameraCaptureTask;
public Transaction()
{
InitializeComponent();
cameraCaptureTask = new CameraCaptureTask();
cameraCaptureTask.Completed += new EventHandler<PhotoResult>(cameraCaptureTask_Completed);
}
void cameraCaptureTask_Completed(object sender, PhotoResult e)
{
if (e.TaskResult == TaskResult.OK)
{
//Code to display the photo on the page in an image control named myImage.
System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
bmp.SetSource(e.ChosenPhoto);
pic.Source = bmp;
pic_name = "" + DateTime.Now.Month + "" + DateTime.Now.Hour + "" + DateTime.Now.Minute + "" + DateTime.Now.Second+".jpeg";
SaveToIsolatedStorage(e.ChosenPhoto, "" + pic_name);
}
}
I'm making a windows phone 8 app of an app I made for windows store, and I am using PhotoChooser task to let the user upload a profile picture.
In the store version i used streams and FileOpenPicker, but i don't know how to use streams with PhotoChooser task.
This is how i did it in windows store, and its perfect:
StorageFile image;
public bunForm()
{
image = null;
this.InitializeComponent();
}
private async void choosePic(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
openPicker.ViewMode = PickerViewMode.Thumbnail;
// Filter to include a sample subset of file types
openPicker.FileTypeFilter.Clear();
openPicker.FileTypeFilter.Add(".bmp");
openPicker.FileTypeFilter.Add(".png");
openPicker.FileTypeFilter.Add(".jpeg");
openPicker.FileTypeFilter.Add(".jpg");
// Open a stream for the selected file
var file = await openPicker.PickSingleFileAsync();
if (file != null)
{
image = file;
var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
bunPic.Visibility = Visibility.Visible;
// Ensure a file was selected
if (file != null)
{
// Ensure the stream is disposed once the image is loaded
using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
{
// Set the image source to the selected bitmap
BitmapImage bitmapImage = new BitmapImage();
await bitmapImage.SetSourceAsync(fileStream);// bitmapImage.UriSource.ToString();
bunPic.Source = bitmapImage;
}
}
}
}
And here is how i'm trying it at windows Phone 8:
But (openPicker.PickSingleFileAsync();) line gives me error.
public BunForm()
{
InitializeComponent();
image = null;
this.photoChooserTask = new PhotoChooserTask();
this.photoChooserTask.Completed += new EventHandler<PhotoResult>(photoChooserTask_Completed);
}
StorageFile image;
private void choosePic(object sender, RoutedEventArgs e)
{
photoChooserTask.Show();
}
private async void photoChooserTask_Completed(object sender, PhotoResult e)
{
//this is the only line that gives me error
var file = await openPicker.PickSingleFileAsync();
///
if (file != null)
{
image = file;
var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
if (file != null)
{
// Ensure the stream is disposed once the image is loaded
using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
{
MessageBox.Show(e.ChosenPhoto.Length.ToString());
//Code to display the photo on the page in an image control named myImage.
System.Windows.Media.Imaging.BitmapImage bmp = new System.Windows.Media.Imaging.BitmapImage();
bmp.SetSource(e.ChosenPhoto);
myImage.Source = bmp;
}
}
}
Debug.WriteLine("pic done");
}
I was wondering how i can save the image in storage file in windows phone 8?
As noted on MSDN pages - OpenFilePicker cannot be used in C# WP8 apps, but you can use the PhotoChooserTask with ease for uploadng the profile picture:
// first invoke the task somewhere
PhotoChooserTask task = new PhotoChooserTask();
task.Completed += task_Completed;
task.Show();
// handle the result
async void task_Completed(object sender, PhotoResult e)
{
// no photo selected
if (e.ChosenPhoto == null) return;
// get the file stream and file name
Stream photoStream = e.ChosenPhoto;
string fileName = Path.GetFileName(e.OriginalFileName);
// persist data into isolated storage
StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
using (Stream current = await file.OpenStreamForWriteAsync())
{
await photoStream.CopyToAsync(current);
}
...
// how to read the data later
StorageFile file2 = await ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
Stream imageStream = await file2.OpenStreamForReadAsync();
// display the file as image
BitmapImage bi = new BitmapImage();
bi.SetSource(imageStream);
// assign the bitmap to Image in XAML: <Image x:Name="img"/>
img.Source = bi;
}
Accoriding to this
Windows Phone 8
This API is supported in native apps only.
You can't use FileOpenPicker class.
There are already answers to the problem OpenFilePicker not working
I just want to save some string into the local folder in a metro app, the code goes:
public GroupedItemsPage()
{
this.InitializeComponent();
Loaded += OnLoaded;
}
async private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
{
var storageFolder = ApplicationData.Current.LocalFolder;
var file = await storageFolder.CreateFileAsync("news.json", CreationCollisionOption.ReplaceExisting);
await FileIO.WriteTextAsync(file, "test");
}
But always got an FileNotFoundException exception, I'm creating a file instead of getting a file, so I don't know what's wrong with this code snippet.
Could anybody show me how to fix this problem? Thx in advance.