mercredi 18 février 2015

Detecting audio track playing from background app in iOS Swift

I'm creating a mood tracking app that, among other things, should use information about the songs the user listens to. Specifically, I'm interested in just extracting the titles that are otherwise visible from the locked screen view, when a track is playing. I've search the interwebs and have had no luck finding a solution to access this data using Swift.


Can anyone help?


How to interrcept and read audio data as it is being output in RaspberryPi

Specifically, I want to write a program to read audio data that is being output to the analog jack on a RaspberryPi that is running Pi MusicBox for a led visualizer. Previously I had a Processing sketch that could run on your average computer, but I am less experienced with ARM. I've considered writing a Java program to do this, but I haven't been able to find any good documentation.


Any help much appreciated, thanks!


mardi 17 février 2015

How do I stop playing a sound effect with SpriteKit and Swift?

I'm writing a storybook app for my niece and I have a question about SpriteKit. I'm trying to set it so that there are different types of audio that play.



  1. Background music that loops (AVFoundation)

  2. Narration that plays when on a new page, or when you press the narrate button to replay the narration (SKAction)


My problem is that the narration will play on top of each other if the user changes the page, or if the user plays the replay narration button. So it ends up sounding like two people talking over each other.


How can I stop all narrations that are playing when a new narration is triggered?


I can't find any relevant help on the internet. I've seen some posts saying us AVFoundation, but from my understanding (albeit limited) that seems more for the background music and can only have one track playing.


Am I misinterpreting the documentation? Can someone help me answer this problem?



import SpriteKit


import AVFoundation


class Page1: SKScene {



// MARK: Touch handling

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
/* Called when a touch begins */

for touch: AnyObject in touches {
let location = touch.locationInNode(self)
println("\(location)")

//checks if someone touched the menu button
if menuButton.containsPoint(location) {
println("Play story with sound!")
settings.setInProgress()
goToPauseMenu()
}

if soundButton.containsPoint(location) {
println("Play story with sound!")
settings.setInProgress()
runAction(playNar)
}

//checks if someone touched the forward button
if pageForward.containsPoint(location) {
println("Next Page!")
settings.setInProgress()
nextPage()
}

}
}

Android media player : Stop buffering of audio stream on pause()

I am using Media player in my application, My application is totally depend on media player. I am streaming the music from the server. however, the streaming working perfectly.But I have to do some optimization as part of better performance of app and load balancing.I have to Stop buffering while user pause the music player.


Currently While i am playing the music player, music player Buffering can't stop while i pause the player. there is need to save bandwidth of the stream.It will save user data usage.and also server will save some process.


Please give me way how to stop buffering while music player pause?


however buffer will release on stop of music player.


My code is below



private MediaPlayer mMediaPlayer;
public String path = "mp3url";


mMediaPlayer = new MediaPlayer(this);
mMediaPlayer.setDataSource(path);
mMediaPlayer.prepare();
mMediaPlayer.start();

mMediaPlayer.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {

@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
// TODO Auto-generated method stub
Log.d("LOG", "Biffering update ||| "+percent);// it show that buffering cann't stop after pausing mediaplayer
}
});

Can't get jquery on click code to work

I'm having a problem with a piece of code which plays a short mp3/ogg file when a font awesome volume icon is clicked. The html works OK. The problem is with the js code



<p id="pathVar">/templates/beez_20/audio/dialogs/buy_flowers/</p>
<div id="dialog">
<div id="title_block">Buying flowers </div>
<div id="dlg_container">
<div id="audio_player" >{audio}Buying flowers|dialogs/buying_flowers/buying_flowers.mp3{/audio}</div>
<p class="dlg_content eng_dlg"><span class="dlg_text" id="bf01">Shopkeeper: Good afternoon, how can I help you?</span>&#xa0;<span class ="fa fa-volume-up fa-volume-up-dlg"></span> </p>
<p class="dlg_content eng_dlg"><span class="dlg_text">สวัสดีตอนบ่าย,มีอะไรให้ฉันช่วยไหม?</span></p>
...
</div></div>


js code



jQuery.noConflict();
jQuery(document).ready(function() {
jQuery("div#dlg_container").on("click",function (evnt) {
var elementId = evnt.target.id,
pathVar = document.getElementById("pathVar").innerHTML,
oggVar = pathVar+elementId+".ogg",
mp3Var = pathVar+elementId+".mp3",
audioElement = document.createElement("audio");
audioElement.src = Modernizr.audio.ogg ? oggVar : mp3Var;
audioElement.load();
audioElement.play();
});
});


Firebug shows that the elementId variable is nil, whereas it should contain, in example above, "bf01". I can't see why this is the case as similar code elsewhere works. I guess I'm missing something obvious here. Thanks in advance for any help.


Android, AOA2, USB Isochronous Audio Streaming

Using AOA v2 protocol, a android device can output its audio stream to some accessory connected over an USB. But is it possible for the accessory to send over its audio stream to android device so that the android device will act as an USB speaker?


I'm actually planning to write a USB speaker driver using AOA protocol, but I just got stuck here. Because I can make the device initialize in AOA mode, but can't get the endpoints for audio interface. So I kind of leaning towards to believe that audio input to android device isn't possible using AOA. Anyone has any experience with that?


How store iOS audio recordings on Parse?

Newbie iOS coder here, apologies if the answer is really simple.


So I set up my audio recording in viewDidLoad



// Set the audio file
NSArray *pathComponents = [NSArray arrayWithObjects:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
@"MyAudioMemo.m4a",
nil];
NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];

// Setup audio session
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];

// Define the recorder setting
NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];

[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];

// Initiate and prepare the recorder
recorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:NULL];
recorder.delegate = self;
recorder.meteringEnabled = YES;
[recorder prepareToRecord];


I have a bar button that records new audio files:



// Stop the audio player before recording
if (player.playing) {
[player stop];
}

if (!recorder.recording) {
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setActive:YES error:nil];

// Start recording
[recorder record];

} else {

// Pause recording
[recorder pause];
}

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Stop" style:UIBarButtonItemStylePlain target:self
action:@selector(stopTapped)];


Then the start becomes a stop button



[recorder stop];

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setActive:NO error:nil];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"New" style:UIBarButtonItemStylePlain target:self
action:@selector(actionNew)];


How can I add this as a PFFile and save in a dictionary in Parse? I've read through a lot of the Parse documentation but still don't really get the hang of it. Any help much appreciated.