Pause/resume the current playing song in Windows Phone - windows-phone-7

I want to write a method in a Windows Phone Application to pause the current playing song and to resume the song if it has paused.
Like a play/pause button.
What is the simplest way to achieve this?

If you want to get it done with the help of the songs stored in the media library the n its easy with the help of MedaPlayer
Use this namespace
using Microsoft.Xna.Framework.Media;
To get all the songs in the media library
MediaLibrary mLibrary = new MediaLibrary();
SongCollection songs= mLibrary.Songs;
To play a specific song
MediaPlayer.Play(songs, int index);
To Pause the mediaplayer
MediaPlayer.Pause();
To continue playing the song
MediaPlayer.Play(songs);
A simple demo as well.

Related

How do I add song to iTunes' "Up Next" with Applescript

I'm pretty new to Applescript (literally just started today), but I can not find out how to just play an album without having to create a playlist with only one album and play that playlist. Essentially I've figured out how to search for what I want and play something, but I can only play one song at a time.
tell application "iTunes"
set search_results to (search playlist "Library" for "Monument Valley (Original Soundtrack)")
repeat with i in search_results
play i
end repeat
end tell
If I do this, it runs through every song until it hits the last one and the last one is played. I believe you can use next track in order to add something to the "Up Next", but I haven't gotten it to work. Is there a way to actually do this or do I have to succumb to playing a playlist?
Sadly, the iTunes AppleScript dictionary has no "terminology" for the Up Next queue. Even Doug's AppleScripts for iTunes, the iTunes scripting authority, has no scripts for Up Next. The next track command is just to "advance to the next track in the current playlist"— equivalent to pressing the "next" button. It seems the only way to script Up Next would be to use GUI scripting, meaning you would tell AppleScript which buttons in the Graphical User Interface to click instead of using an API. This can be quite difficult, so I think you'll have better luck if you just succumb to using playlists. Fortunately, the iTunes dictionary does include plenty of controls for creating and manipulating playlists.

How do I close a form when windows media player finishes video playlist?

I have a form where a button opens a dialogue box and the user can select multiple videos to play. The code puts the videos into a playlist and opens a new form with axwindowsmediaplayer embedded to play the video.
I am trying to close the player form when the playlist ends. I can close the form using a playstate change event if I only select one video, but can't figure out how to close the form for multiple video files in the playlist.
I have tried using timers to keep checking the play list, but have not had any luck. Can anyone point me in the right direction in closing a form after the video playlist ends?

Cannot play album with AVAudioPlayer

I'm working on a very simple OSX application that will allow me to play either a song or a folder of songs.
I can choose a song and play it and everything is fine. I can choose a folder and create an array of songs and... play the last one.
var currentSong: NSURL?
var album: [NSURL] = []
var audioPlayer = AVAudioPlayer()
My playing function is
func playCurrent(){
do {
try audioPlayer = AVAudioPlayer(contentsOfURL: currentSong!)
} catch {
print("Ignoring errors for now")
}
audioPlayer.play()
}
This works fine whenever I set currentSong to a NSURL. I choose one song, it plays it.
My album function is as follows:
#IBAction func chooseAlbumAndPlay(sender: AnyObject) {
album = albumFromFile()
for song in album {
currentSong = song
playCurrent()
}
}
and here I have the problem. albumFromFile opens an NSOpenPanel, lets me choose a folder, and dumps paths to playable items into an array of NSURLs. This part works, I've verified it, so I really have an array with 12 or 20 or whatever correct, playable URLs. If I just run it as is, only the last song in any album gets played. If I set a breakpoint in the playCurrent() function, I can hear that it will actually play a tiny snippet - less than a note in most cases - of all songs but the last.
According to the documentation, play() returns a boolean - and it will happily report that it has finished playing every song in this loop.
My - human - opinion is that a song has only finished playing when I have heard all of it.
If I query the duration of the current AVAudioPlayer, they all report perfectly reasonable-sounding values.
I'm completely stumped here. PlayCurrent seems to completely fail to assert itself as a running function. The expected behaviour is that it will not exit until play() has finished playing; observed behaviour is that it will touch every song for the briefest time, go 'been there' and return to the enclosing loop.
How can I force AVAudioPlayer to play the whole of a file before exiting my playCurrent() function? And where would I have found that information? (The class documentation is unhelpful, the mentioned audio guides do not exist - right now, the Developer Library does not mention any basic audio guides for OSX.
The answer is, once you get around to it, very obvious indeed. Unfortunately, the documentation really is no help at all. I could, in theory, have found the solution by looking at the entry for AVAudioPlayer in the AVFoundationFramework reference, but I didn't. (I found it by wildly casting about and a chance mention).
There appear to be no working OSX examples; Apple's iOS example uses the MediaPlayer framework that is not available on OSX.
The solution is as follows:
An AVAudioPlayer plays a single sound.
If you want to play more than one sound, you need an AVQueuePlayer which can also play a single sound from a URL or a queue of AVPlayerItems (this class has an init(URL:) method).
If anyone has an idea why AVAudioPlayer behaves as it does, I'm still interested to hear it.

Microphone not working when a call occures

I m trying to record a voice using Microphone API in WP7/WP8.
Every thing is working fine when i use it to record a normal voice, but when i use it when a call is answered the application is running well. but when i playback that recorded voice the whole recording is empty, there is no sound at all.
what happened with the microphone in this case?
here is the code which i m using
microphone.BufferDuration = TimeSpan.FromMilliseconds(100);
microphone.Start();
void micro_BufferReady(object sender, EventArgs e)
{
audioBuffer = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)];
microphone.GetData(audioBuffer);
currentRecordingStream.Write(audioBuffer, 0, audioBuffer.Length);
}
You can't record a call with the microphone in your app. When a call is activated, the call app on the phone take control of the Microphone and the sound is directed to it, not to your application.

Uniquely identify albums and songs in Windows Phone media library

I am importing a songs collection from an Album object that is obtained from querying MediaLibrary on Windows Phone Mango.
Is there a unique identifier provided by the platform, by which I could be identifying different songs and albums?
I need something that will remain the same for the same albums if I re-query the MediaLibrary next time my app is ran.
I have seen a "handle" property in the debugger, but it doesn't appear in any of the Album class documentation.
I'd try GetHashCode() for Song and Album. At least Song overrides this function directly, so hopefully it is computed from the song's properties.

Resources