In MVVM, play media file from Model or ViewModel? - c#

This question is not related to the MediaElement—pertaining to this, I’ve read both MediaElement.play() from within ViewModel and MVVM pattern violation: MediaElement.Play(), and I agree with both of them.
But say that we’re using instead a third-party assembly such as NAudio. We don’t have to find a way of plugging an existing XAML media control’s interactive features into our ViewModel. Instead, we can simply use, e.g., InteractionTriggers in our View, subscribe to it in our ViewModel, and invoke the play command on a given media file.
Now my question is: is this still something that fits, within the MVVM pattern, into the ViewModel? Or should we rather hand this down to the Model and play the file from there?

I would say it entirely depends on the nature of the media file and its relation to your app's core logic.
Is it just a UI feedback sound effect that gets played when you click on something? Stays in the view.
Is it a music player app that plays music from a playlist? That's core logic and belongs in the VM.
If I'm unsure where something lives, I think about an imaginary "view" on my app that uses a text console rather than WPF. If the logic still exists even if driven by a console, then it lives in the VM.

Related

using playbackagent for windows phone 8.1 in MVVM Pattern

I'm trying to play audio in background, I have made a project using MVVM light Desing pattern. After some research I found this sample that helped to implement playbackagent in windows phone 8.1!
My goal is to implement the Agent in my solution with MVVM Pattern.
Could someone help me with that?
I can provide some general rules:
Put business logic / condictional code into the ViewModel.
Your View (.xaml.cs) files should only have minimum and necessary code for UI
Use the service locator to always have one instance of the music player (which can be warped inside a controller).
Use Messenger service to send data / notify the player from difference view models

Passing data between WPF and class

I'm facing a problem where I don't know on how to implement the WPF. I admit to be pretty new to WPF.
I got a complex project which I abstract here a lot. The project is to manage a lot of different usb devices. This device are managed within one class ("manager-class") which handles connecting, disconnecting, settings for the devices, receiving data and more automated routines.
I created a WPF but I'm not sure on how to get the data into the WPF as a lot of things (connecting/disconnecting/updates) I need to show live on the WPF. I started by creating some dockpanels within the C#-code of the WPF. This works in order to build up the startup structure. The problem I'm facing is to send a signal to the WPF that "manager-class" got updated and I also have to update the WPF (add panels, set checkboxes etc.).
I appreciate any hint as I don't really have starting point to implement this.
Take a look (google or bing) at databinding,INotifyPropertyChanged and observable objects and collections in context with WPF. You'll find tons...
Here is a example of simple data binding http://blogs.msdn.com/b/wpfsdk/archive/2006/10/19/wpf-basic-data-binding-faq.aspx
When you feel save enough with this I would suggest to research for MVVM. This pattern helps a lot in XAML based languages to structure and seperate concerns of your code...
HTH

3D Model with Monodroid

I'm interested in adding a 3d model into my Android app which is being developed in Mono with c#. The model will be developed with a tool like Blender. An example of the interaction with the model would be clicking a "smile" button and initiating the models smile sequence. Is there a clever "container" for this type of media? I only need to show the user pre-determined routines - they won't be creating new ones.
Thanks for any help.
You may need to make use of OpenTK library, which is C# wrapper over OpenGL.
You may want to have also some importers for the file format you're going to operate on.
This is just an exaple of a simple Cube, from xamarin site itself:
Hello GLCube

Using Monocross on Windows Phone 7 with Panorama and/or Pivot control

I love the Monocross idea but am a bit lost for Windows Phone 7 when I want to use a Panorama and/or Pivot control. The only view provided is the Page view. So navigating from one page to another works great! But now I want a Pivot or Panorama. Basically I could create a new controller for this view, but do get the "pages" inside the controls. The navigate does really Navigate to it, but not inside the Pivot / Panorama.
For Monotouch and MonoDroid samples have been prepared how to do this (basically a new viewcontroller was created). But WP7 has been left behind.
Anybody?
I am also doing cross platform development using mono and like you and many others face the problem of what to do with respect to the user interface and other underlying hardware integration.
I decided that I did not want to be at the mercy of yet another third party framework (mono is enough) and researched for a solution that I could build and maintain myself. The new MVVM pattern along with Expression Blend is really cool but soon you find yourself stuck when it comes to cross platform development.The MVC an MVP patterns also did not seem to suit what I needed. Finally settled on the PM pattern and expanded it into a PMH where the H is for hardware. To achieve what I needed I had to abstract the fundamental widgets (buttons, panels, textboxes) into a underlying platform layer for each device type. My platform layer represents around 1% of my code base and allows me to skin the application for each device I target it for.
For my WP7 solution I use hardly any HTML only around 25 lines which is enough to initialise the application and the main page. The rest of the user interface is put together programmatically just like I would in WinForms. On WP7 I still make use of the Pivot control as it really is pretty groovy and am modelling a similar control for use on Android/iPhone. While it wont be 100% the same it will be very similar and still use the same navigation engine within my core code.
I am not complete with my development yet but so far I am very happy with my progress. I have been developing user interface for Windows application for some 20 years and I never use the interface builder tools as I find they never give me what I want and really waste my time (Blend is pretty cool though) and also create a tremendous code bloat especially in Blend.
I can't entirely help with monocross - I did do a sample for droid once - https://github.com/slodge/monocross-tab-activity-view - but I never completed the wp7 part of that.
For mvvmcross... which is related... there's a couple of samples - one in the tutorial (a bit hacky!) and one in the conference app - much the preferred sample.
The basic technique I choose was to use sub-viewmodels for each "tab" of the panorama - see how the databinding DataContext is set for each Item in https://github.com/slodge/MvvmCross/blob/master/Sample%20-%20CirriousConference/Cirrious.Conference.UI.WP7/Views/HomeView.xaml
Note that in a bigger app there may be important memory issues to consider when doing this - especially when using a pivot control which does not load all pages into memory at the same time (so you don't really need to load all viewmodels either)
Some bloggage on the conf app: http://slodge.blogspot.co.uk/2012/03/update-on-mvvmcross-sqlbits-conference.html
And the final sql bits source: https://github.com/slodge/MvvmCross/tree/master/Sample%20-%20CirriousConference

Good framework for a C# developer to use for visually stunning presentation layer

I am about to write a front end app, which will be used as a media center app. It will plug directly into a high definition TV. Essentially transforming my laptop into a media player. While this concept is not new, I want custom functionality, so this is why I am not reusing existing products.
I'm a C# developer, so the app should ideally be written in C#. And there is 1 other consideration, I need to accept input via the MCE Remote.
I was considering using Silverlight for this. Would you recommend this? Or any other recommendations for frameworks before I begin planning around this.
Thanks in advance.
This is the type of stuff that the Windows Presentation Foundation was meant for. You'll get a lot more access to the hardware than Silverlight would provide (I.E. that MCE remote you mentioned). You mark up your UI with vector graphics/XAML, and then perform the logic with C#.
EDIT: WPF also has support out of the box for animations which can make your UI a lot more interactive.
EDIT 2: Scott Hanselman has written a really cool application called BabySmash and posted the source online. It basically intercepts keyboard input and shows shapes and sounds on the computer. It's a good "child-proofing" method for your PC. The code could provide you with some insight into WPF and how to do the animations and interactivity that you're looking for.
Is this a desktop app? If so I would use WPF. Silverlight is a subset of WPF, so using WPF you could potentially do more.
Silverlight or WPF, if you want some extra power. Both have a similar programming model (with XAML and code-behind) so you might be able to start with Silverlight and move up to WPF if you need.
The VLC api might be useful for playing your media, someone has created a C# wrapper for it:
http://wiki.videolan.org/.Net_Interface_to_VLC
WPF is certainly the way to go, and for playing media check out the excellent WPF MediaKit: http://wpfmediakit.codeplex.com/ I've used it successfully in many projects.

Categories

Resources