本文整理汇总了C#中Microsoft.Xna.Framework.Media.MediaLibrary类的典型用法代码示例。如果您正苦于以下问题:C# MediaLibrary类的具体用法?C# MediaLibrary怎么用?C# MediaLibrary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MediaLibrary类属于Microsoft.Xna.Framework.Media命名空间,在下文中一共展示了MediaLibrary类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetPicturesAsync
/// <summary>
/// Asynchronously returns a list of all pictures in the specified album
/// </summary>
/// <param name="albumName">The name of the album</param>
/// <param name="path">The path of the album</param>
/// <returns>A list of all pictures in the specified album</returns>
/// <remarks>The path parameter is not actually used in this Windows Phone implementation
/// since the MediaLibrary API does not support picture or album retrieval with a path. Instead, we must walk
/// the library looking for the album with the given albumName and then grab all the pictures in that album.</remarks>
public Task<List<PictureViewModel>> GetPicturesAsync(string albumName, string path)
{
return Task.Run(delegate
{
List<PictureViewModel> result = new List<PictureViewModel>();
MediaLibrary mediaLib = new MediaLibrary();
// Find the album
foreach (var album in mediaLib.RootPictureAlbum.Albums)
{
// Because the photo library API on Windows Phone doesn't expose the concept of "path",
// we iterate and find the album based on the name.
if (album.Name == albumName)
{
foreach (var pic in album.Pictures)
{
PictureViewModel pvm = new PictureViewModel(App.PictureService, albumName, pic.Name,String.Format("{0}|{1}",albumName, pic.Name),pic.Width, pic.Height);
result.Add(pvm);
}
Debug.WriteLine("{0} pictures in {1}", result.Count(), albumName);
break;
}
}
return result;
});
}
开发者ID:janaknm,项目名称:HelloWorld,代码行数:35,代码来源:AlbumService.cs
示例2: TakeInIsolatedSotrage
public static String TakeInIsolatedSotrage(UIElement elt, String name)
{
string imageFolder = "Shared/ShellContent/";
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!myIsolatedStorage.DirectoryExists(imageFolder))
{
myIsolatedStorage.CreateDirectory(imageFolder);
}
if (myIsolatedStorage.FileExists(name))
{
myIsolatedStorage.DeleteFile(name);
}
string filePath = System.IO.Path.Combine(imageFolder, name);
IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(filePath);
var bmp = new WriteableBitmap(elt, null);
var width = (int)bmp.PixelWidth;
var height = (int)bmp.PixelHeight;
using (var ms = new MemoryStream(width * height * 4))
{
bmp.SaveJpeg(ms, width, height, 0, 100);
ms.Seek(0, SeekOrigin.Begin);
var lib = new MediaLibrary();
Extensions.SaveJpeg(bmp, fileStream, width, height, 0, 80);
}
fileStream.Close();
Debugger.Log(0, "", "isostore:/" + filePath);
return "isostore:/"+filePath;
}
}
开发者ID:fstn,项目名称:WindowsPhoneApps,代码行数:33,代码来源:ScreenShot.cs
示例3: OnNavigatedTo
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
// Get a dictionary of query string keys and values.
IDictionary<string, string> queryStrings = this.NavigationContext.QueryString;
// Check whether the app has been started by the photo edit picker of the Windows Phone System
// More information about the photo edit picker here: http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202966(v=vs.105).aspx
if (queryStrings.ContainsKey("FileId") && imageAlreadyLoaded == false)
{
imageAlreadyLoaded = true;
// Retrieve the photo from the media library using the FileID passed to the app.
MediaLibrary library = new MediaLibrary();
Picture photoFromLibrary = library.GetPictureFromToken(queryStrings["FileId"]);
// Create a BitmapImage object and add set it as the PreviewImage
BitmapImage bitmapFromPhoto = new BitmapImage();
bitmapFromPhoto.SetSource(photoFromLibrary.GetPreviewImage());
SetPreviewImage(bitmapFromPhoto);
}
// Every time we navigate to the MainPage we check if a filter has been selected on the FilterView page
// If so, we apply this filter to the PreviewImage
if (FilterSelectorView.SelectedFilter != null)
{
await ApplyFilter(FilterSelectorView.SelectedFilter, PreviewPicture);
}
}
开发者ID:robinmanuelthiel,项目名称:Instagram-In-One-Hour,代码行数:29,代码来源:MainPage.xaml.cs
示例4: OnPhotoChooserTaskCompleted
private void OnPhotoChooserTaskCompleted(object sender, PhotoResult e)
{
var stream = e.ChosenPhoto;
if (stream == null)
{
// If connected to Zune and debugging (WP7), the PhotoChooserTask won't open so we just pick the first image available.
#if DEBUG
var mediaLibrary = new MediaLibrary();
if (mediaLibrary.SavedPictures.Count > 0)
{
var firstPicture = mediaLibrary.SavedPictures[0];
stream = firstPicture.GetImage();
}
#else
return;
#endif
}
var bitmapImage = new BitmapImage();
bitmapImage.SetSource(stream);
//TODO: close stream?
_writableBitmap = new WriteableBitmap(bitmapImage);
pixelatedImage.Source = _writableBitmap;
_originalPixels = new int[_writableBitmap.Pixels.Length];
_writableBitmap.Pixels.CopyTo(_originalPixels, 0);
PixelateWriteableBitmap();
}
开发者ID:petermorlion,项目名称:EightBitCamera,代码行数:30,代码来源:Existing.xaml.cs
示例5: OnNavigatedTo
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
MediaLibrary library = new MediaLibrary();
if (NavigationContext.QueryString.ContainsKey(playSongKey))
{
// Start über Hub-Verlauf
// playingSong direkt übernehmen und starten
string songName = NavigationContext.QueryString[playSongKey];
playingSong = library.Songs.FirstOrDefault(s => s.Name == songName);
isFromHubHistory = true;
}
else if (MediaPlayer.State == MediaState.Playing)
{
// Aktuellen Song übernehmen
playingSong = MediaPlayer.Queue.ActiveSong;
}
else
{
// Zufälligen Song auswählen
Random r = new Random();
int songsCount = library.Songs.Count;
if (songsCount > 0)
{
playingSong = library.Songs[r.Next(songsCount)];
}
else
{
SongName.Text = "Keine Songs gefunden";
Play.IsEnabled = false;
}
}
}
开发者ID:GregOnNet,项目名称:WP8BookSamples,代码行数:34,代码来源:MainPage.xaml.cs
示例6: saveButton_Click
/// <summary>
/// Clicking on the save button saves the photo in DataContext.ImageStream to media library
/// camera roll. Once image has been saved, the application will navigate back to the main page.
/// </summary>
private void saveButton_Click(object sender, EventArgs e)
{
try
{
// Reposition ImageStream to beginning, because it has been read already in the OnNavigatedTo method.
_dataContext.ImageStream.Position = 0;
MediaLibrary library = new MediaLibrary();
library.SavePictureToCameraRoll("CameraExplorer_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpg", _dataContext.ImageStream);
// There should be no temporary file left behind
using (var isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
var files = isolatedStorage.GetFileNames("CameraExplorer_*.jpg");
foreach (string file in files)
{
isolatedStorage.DeleteFile(file);
//System.Diagnostics.Debug.WriteLine("Temp file deleted: " + file);
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Saving picture to camera roll failed: " + ex.HResult.ToString("x8") + " - " + ex.Message);
}
NavigationService.GoBack();
}
开发者ID:flair2005,项目名称:RGBDVideoStreams,代码行数:33,代码来源:PreviewPage.xaml.cs
示例7: GetAlbumsAsync
/// <summary>
/// Asynchronously returns a list of all albums in the picture library
/// </summary>
/// <returns>A list of all albums in the picture library</returns>
public Task<List<PixPresenterPortableLib.AlbumViewModel>> GetAlbumsAsync()
{
return Task.Run(delegate
{
List<AlbumViewModel> result = new List<AlbumViewModel>();
MediaLibrary mediaLib = new MediaLibrary();
foreach (var album in mediaLib.RootPictureAlbum.Albums)
{
byte[] thumb = null;
// Exclude empty picture albums
if (album.Pictures.Count > 0)
{
Stream stream = album.Pictures[0].GetThumbnail();
using (BinaryReader br = new BinaryReader(stream))
{
thumb = br.ReadBytes((int)stream.Length);
}
AlbumViewModel avm = new AlbumViewModel(App.AlbumService, album.Name, album.Name, thumb);
avm.Name = album.Name;
result.Add(avm);
}
}
return result;
});
}
开发者ID:janaknm,项目名称:HelloWorld,代码行数:32,代码来源:AlbumsService.cs
示例8: MatchLocalPathWithLibraryPath
public static string MatchLocalPathWithLibraryPath(string localPath)
{
var localFilename = FilenameFromPath(localPath);
using (var library = new MediaLibrary())
{
using (var pictures = library.Pictures)
{
for (int i = 0; i < pictures.Count; i++)
{
using (var picture = pictures[i])
{
var libraryPath = picture.GetPath();
var libraryFilename = FilenameFromPath(libraryPath);
if (localFilename == libraryFilename)
{
return libraryPath;
}
}
}
}
}
return null;
}
开发者ID:morefun0302,项目名称:photo-inspector,代码行数:26,代码来源:Mapping.cs
示例9: OnNavigatedTo
protected override void OnNavigatedTo(NavigationEventArgs e)
{
imageDetails.Text = "";
IDictionary<string, string> queryStrings =
NavigationContext.QueryString;
string token = null;
string source = null;
if (queryStrings.ContainsKey("token"))
{
token = queryStrings["token"];
source = "Photos_Extra_Viewer";
}
else if (queryStrings.ContainsKey("FileId"))
{
token = queryStrings["FileId"];
source = "Photos_Extra_Share";
}
if (!string.IsNullOrEmpty(token))
{
MediaLibrary mediaLib = new MediaLibrary();
Picture picture = mediaLib.GetPictureFromToken(token);
currentImage = ImageUtil.GetBitmap(picture.GetImage());
photoContainer.Fill = new ImageBrush { ImageSource = currentImage };
imageDetails.Text = string.Format("Image from {0}.\nPicture name:\n{1}\nMedia library token:\n{2}",
source, picture.Name, token);
}
imageDetails.Text += "\nUri: " + e.Uri.ToString();
}
开发者ID:whrxiao,项目名称:Windows-Phone-7-In-Action,代码行数:32,代码来源:MainPage.xaml.cs
示例10: PlayMusic
/// <summary>
/// Sets the background music to the sound with the given name.
/// </summary>
/// <param name="name">The name of the music to play.</param>
public static void PlayMusic(string name)
{
currentSong = null;
try
{
currentSong = content.Load<Song>(name);
}
catch (Exception e)
{
#if ZUNE
//on the Zune we can go through the MediaLibrary to attempt
//to find a matching song name. this functionality doesn't
//exist on Windows or Xbox 360 at this time
MediaLibrary ml = new MediaLibrary();
foreach (Song song in ml.Songs)
if (song.Name == name)
currentSong = song;
#endif
//if we didn't find the song, rethrow the exception
if (currentSong == null)
throw e;
}
MediaPlayer.Play(currentSong);
}
开发者ID:danielselnick,项目名称:Sentry-Smash,代码行数:31,代码来源:soundm.cs
示例11: saveImageDataToLibrary
public void saveImageDataToLibrary(string jsonArgs)
{
try
{
var options = JsonHelper.Deserialize<string[]>(jsonArgs);
string imageData = options[0];
byte[] imageBytes = Convert.FromBase64String(imageData);
using (var imageStream = new MemoryStream(imageBytes))
{
imageStream.Seek(0, SeekOrigin.Begin);
string fileName = String.Format("c2i_{0:yyyyMMdd_HHmmss}", DateTime.Now);
var library = new MediaLibrary();
var picture = library.SavePicture(fileName, imageStream);
if (picture.Name.Contains(fileName))
{
DispatchCommandResult(new PluginResult(PluginResult.Status.OK,
"Image saved: " + picture.Name));
}
else
{
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR,
"Failed to save image: " + picture.Name));
}
}
}
catch (Exception ex)
{
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, ex.Message));
}
}
开发者ID:Jypy,项目名称:zmNinja,代码行数:34,代码来源:Canvas2ImagePlugin.cs
示例12: Button_Click
private void Button_Click(object sender, RoutedEventArgs e)
{
var api = ((App)App.Current).Api;
api.CatalogUpdateCompleted += new EventHandler<EchoNestApiEventArgs>(api_CatalogUpdateCompleted);
var songsActions = new List<CatalogAction<BMSong>>();
using (var mediaLib = new MediaLibrary())
{
foreach (var song in mediaLib.Songs)
{
var catalogAction = new CatalogAction<BMSong>();
catalogAction.Action = CatalogAction<BMSong>.ActionType.update;
catalogAction.Item = new BMSong
{
ItemId = Guid.NewGuid().ToString("D"),
ArtistName = song.Artist.Name,
SongName = song.Name,
};
songsActions.Add(catalogAction);
}
}
var catalog = new Catalog();
catalog.Id = catalogId.Text;
catalog.SongActions = songsActions;
api.CatalogUpdateAsync(catalog, null, null);
}
开发者ID:hamishhill,项目名称:Beat-Machine,代码行数:29,代码来源:LocalMusicCatalog.xaml.cs
示例13: capture
public static Boolean capture(int quality)
{
try
{
PhoneApplicationFrame frame = (PhoneApplicationFrame)Application.Current.RootVisual;
WriteableBitmap bitmap = new WriteableBitmap((int)frame.ActualWidth, (int)frame.ActualHeight);
bitmap.Render(frame, null);
bitmap.Invalidate();
string fileName = DateTime.Now.ToString("'Capture'yyyyMMddHHmmssfff'.jpg'");
IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
if (storage.FileExists(fileName))
return false;
IsolatedStorageFileStream stream = storage.CreateFile(fileName);
bitmap.SaveJpeg(stream, bitmap.PixelWidth, bitmap.PixelHeight, 0, quality);
stream.Close();
stream = storage.OpenFile(fileName, FileMode.Open, FileAccess.Read);
MediaLibrary mediaLibrary = new MediaLibrary();
Picture picture = mediaLibrary.SavePicture(fileName, stream);
stream.Close();
storage.DeleteFile(fileName);
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return false;
}
return true;
}
开发者ID:miyabi,项目名称:CaptureScreen,代码行数:33,代码来源:CaptureScreen.cs
示例14: TestAddingListOfSongs
public void TestAddingListOfSongs()
{
EZPlaylist playlist = new EZPlaylist("My Awesome Playlist");
MediaLibrary lib = new MediaLibrary();
if (lib.Songs.Count > 1)
{
List<SongInfo> list = new List<SongInfo>();
Song song = lib.Songs[0];
SongInfo si1 = new SongInfo(song.Artist.Name, song.Album.Name, song.Name, song.Duration, song.TrackNumber);
list.Add(si1);
song = lib.Songs[1];
SongInfo si2 = new SongInfo(song.Artist.Name, song.Album.Name, song.Name, song.Duration, song.TrackNumber);
list.Add(si2);
playlist.AddList(list.AsReadOnly());
Assert.IsTrue(playlist.Count == 2);
Assert.IsTrue(playlist.Songs.Contains(si1));
Assert.IsTrue(playlist.Songs.Contains(si2));
}
else
{
Assert.Fail("Can't test adding a song because there are no songs to add or there is only one song.");
}
}
开发者ID:kurkowski,项目名称:EZMedia,代码行数:27,代码来源:TestPlaylistClass.cs
示例15: OnNavigatedTo
// Sample code for building a localized ApplicationBar
//private void BuildLocalizedApplicationBar()
//{
// // Set the page's ApplicationBar to a new instance of ApplicationBar.
// ApplicationBar = new ApplicationBar();
// // Create a new button and set the text value to the localized string from AppResources.
// ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
// appBarButton.Text = AppResources.AppBarButtonText;
// ApplicationBar.Buttons.Add(appBarButton);
// // Create a new menu item with the localized string from AppResources.
// ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
// ApplicationBar.MenuItems.Add(appBarMenuItem);
//}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (State.ContainsKey("customCamera"))
{
State.Remove("customCamera");
InitializeCamera();
}
IDictionary<string, string> queryStrings = NavigationContext.QueryString;
string action = null;
if (queryStrings.ContainsKey("Action"))
action = queryStrings["Action"];
string token = null;
if (queryStrings.ContainsKey("FileId"))
token = queryStrings["FileId"];
if (!string.IsNullOrEmpty(token))
{
MediaLibrary mediaLib = new MediaLibrary();
Picture picture = mediaLib.GetPictureFromToken(token);
currentImage = PictureDecoder.DecodeJpeg(picture.GetImage());
photoContainer.Fill = new ImageBrush { ImageSource = currentImage };
imageDetails.Text = string.Format("Image from {0} action.\nPicture name:\n{1}\nMedia library token:\n{2}", action, picture.GetPath(), token);
}
}
开发者ID:timothybinkley,项目名称:Windows-Phone-8-In-Action,代码行数:43,代码来源:MainPage.xaml.cs
示例16: MainPage
// Constructor
public MainPage()
{
InitializeComponent();
ml = new MediaLibrary();
gm = new List<GalleryModel>();
}
开发者ID:fiefioor,项目名称:XNAmusic,代码行数:8,代码来源:MainPage.xaml.cs
示例17: WebClientOpenReadCompleted
void WebClientOpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
const string tempJpeg = "TempJPEG";
var streamResourceInfo = new StreamResourceInfo(e.Result, null);
var userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication();
if (userStoreForApplication.FileExists(tempJpeg))
{
userStoreForApplication.DeleteFile(tempJpeg);
}
var isolatedStorageFileStream = userStoreForApplication.CreateFile(tempJpeg);
var bitmapImage = new BitmapImage { CreateOptions = BitmapCreateOptions.None };
bitmapImage.SetSource(streamResourceInfo.Stream);
var writeableBitmap = new WriteableBitmap(bitmapImage);
writeableBitmap.SaveJpeg(isolatedStorageFileStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 85);
isolatedStorageFileStream.Close();
isolatedStorageFileStream = userStoreForApplication.OpenFile(tempJpeg, FileMode.Open, FileAccess.Read);
// Save the image to the camera roll or saved pictures album.
var mediaLibrary = new MediaLibrary();
// Save the image to the saved pictures album.
mediaLibrary.SavePicture(string.Format("SavedPicture{0}.jpg", DateTime.Now), isolatedStorageFileStream);
isolatedStorageFileStream.Close();
}
开发者ID:trilok567,项目名称:Windows-Phone,代码行数:30,代码来源:Page1.xaml.cs
示例18: PhoneApplicationPage_Loaded
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
MediaLibrary ml = new MediaLibrary();
List<Song> songlist = ml.Songs.ToList();
albums = new List<AlbumModel>();
String artist_name = null;
if (NavigationContext.QueryString.TryGetValue("Artist", out artist_name))
{
ArtistTextBlock.Text = artist_name;
foreach(Artist a in ml.Artists)
{
if(a.Name == artist_name)
{
foreach (Album item in a.Albums)
{
albums.Add(new AlbumModel(item.Name, item.GetThumbnail()));
}
break;
}
}
AlbumSelector.ItemsSource = albums;
}
}
开发者ID:fiefioor,项目名称:XNAmusic,代码行数:25,代码来源:AlbumPage.xaml.cs
示例19: PopulateImageGrid
private void PopulateImageGrid()
{
MediaLibrary mediaLibrary = new MediaLibrary();
var pictures = mediaLibrary.Pictures;
for (int i = 0; i < pictures.Count; i += Utilities.ImagesPerRow)
{
RowDefinition rd = new RowDefinition();
rd.Height = new GridLength(Utilities.GridRowHeight);
grid1.RowDefinitions.Add(rd);
int maxPhotosToProcess = (i + Utilities.ImagesPerRow < pictures.Count ? i + Utilities.ImagesPerRow : pictures.Count);
int rowNumber = i / Utilities.ImagesPerRow;
for (int j = i; j < maxPhotosToProcess; j++)
{
BitmapImage image = new BitmapImage();
image.SetSource(pictures[j].GetImage());
Image img = new Image();
img.Height = Utilities.ImageHeight;
img.Stretch = Stretch.Fill;
img.Width = Utilities.ImageWidth;
img.HorizontalAlignment = HorizontalAlignment.Center;
img.VerticalAlignment = VerticalAlignment.Center;
img.Source = image;
img.SetValue(Grid.RowProperty, rowNumber);
img.SetValue(Grid.ColumnProperty, j - i);
img.Tap += Image_Tap;
grid1.Children.Add(img);
}
}
}
开发者ID:tiagobabo,项目名称:windows-phone-gallery,代码行数:32,代码来源:LocalStorage.xaml.cs
示例20: MainPage
// Constructor
public MainPage()
{
InitializeComponent();
library = new MediaLibrary();
photoChooser = new PhotoChooserTask();
photoChooser.Completed += photoChooser_Completed;
}
开发者ID:GregOnNet,项目名称:WP8BookSamples,代码行数:8,代码来源:MainPage.xaml.cs
注:本文中的Microsoft.Xna.Framework.Media.MediaLibrary类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论