User Tag List

Results 1 to 2 of 2

Thread: Play music in the background using AVAudioplayer

  1. #1
    Clicker

    Fusion 2.5 MacFusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleUnicode Add-onInstall Creator Pro
    StingRay's Avatar
    Join Date
    Nov 2006
    Location
    Austria
    Posts
    1,096
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)

    Cool Play music in the background using AVAudioplayer

    Hi! I've solved to keep my streaming music playing, even if the app is in background or the lock screen is visible. Please notice, that you have to get your hands dirty and change some lines in xcode.

    may somebody is interested, here's my workflow:

    1. create an app with an >>iOS Video Object<< and select your music (in my case i've selected streaming content of an internet radio station)

    2. export the app to xcode

    3. after opening the project in xcode, add this frameworks:
    "AVFoundation.framework" and "AudioToolbox.framework"

    4. open your app-Info.plist from the Ressources folder and add a line called:
    "UIBackgroundModes", add an item to it called "audio" (both will be renamed by xcode automatically)

    5. open "RuntimeIPhoneAppDelegate.h"

    add to the import lines:
    #import <AVFoundation/AVFoundation.h>

    add after " @ interface" the following
    AVAudioPlayer *audioPlayer; // Plays the audio

    after the next Bracket } add this:
    @property (nonatomic, retain) AVAudioPlayer *audioPlayer;

    6. open "RuntimeIPhoneAppDelegate.m"

    add the following line in the "didFinishLaunchingWithOptions" after the line "[[UIDevice currentDevice] ..."
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:NULL];


    that's it! - hopefully you're golden and can now create music or streaming apps with mmf!

  2. #2
    Clicker

    Fusion 2.5 MacFusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleUnicode Add-onInstall Creator Pro
    StingRay's Avatar
    Join Date
    Nov 2006
    Location
    Austria
    Posts
    1,096
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Add on:

    To resume the audio after an interruption (phone call,...) you have to add some more lines:

    7. open "RuntimeIPhoneAppDelegate.m"
    add this line after "[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:NULL];"
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

    8. at the end of the file, just before "@end" place this:

    - (void)endInterruptionWithFlagsNSUInteger)flags {
    // Validate if there are flags available.
    if (flags) {
    // Validate if the audio session is active and immediately ready to be used.
    if (AVAudioSessionInterruptionFlags_ShouldResume) {
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
    // Resume playing the audio.
    });
    }
    }
    }

Similar Threads

  1. music in MMF2 - can music play across frames
    By RoguePixel in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 5th April 2017, 06:16 PM
  2. [PAID] Seamless Looping OGG/Music Player Extension (to play music with loop points)
    By DinnerSonic in forum Paid Design & Development Requests
    Replies: 0
    Last Post: 6th October 2013, 07:27 PM
  3. How to allow you applications to let background music play
    By Keith in forum iOS Specific Example Files
    Replies: 9
    Last Post: 2nd June 2013, 08:47 PM
  4. no music play in android app
    By ezra in forum Android Export Module Version 2.0
    Replies: 2
    Last Post: 13th April 2013, 07:26 PM
  5. Is there a way to play music over frames ?
    By Rushino in forum Multimedia Fusion 2 - Technical Support
    Replies: 9
    Last Post: 19th October 2006, 08:53 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •