Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7677421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:25:07+00:00 2026-05-31T17:25:07+00:00

My application plays online streams. However when user navigates to the next view controller

  • 0

My application plays online streams.

However when user navigates to the next view controller the music stops. Here is the code that plays sound:

- (void)start
{
    @synchronized (self)
    {
        if (state == AS_PAUSED)
        {
            [self pause];
        }
        else if (state == AS_INITIALIZED)
        {
            NSAssert([[NSThread currentThread] isEqual:[NSThread mainThread]],
                @"Playback can only be started from the main thread.");
            notificationCenter =
                [[NSNotificationCenter defaultCenter] retain];
            self.state = AS_STARTING_FILE_THREAD;
            internalThread =
                [[NSThread alloc]
                    initWithTarget:self
                    selector:@selector(startInternal)
                    object:nil];
            [internalThread setName:@"InternalThread"];
            [internalThread start];
        }
    }
}

I’ve tried :

dispatch_async(dispatch_get_main_queue(), 
                           ^{
                               [internalThread start];
                           });

But it doesn’t work. Does anyone have experience with this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:25:08+00:00Added an answer on May 31, 2026 at 5:25 pm

    You have to keep a reference to your AS object.

    In my case, I’ve wrapped AS in a singleton.

    @implementation MyClass
    
    static AudioStreamer *sharedStreamer = nil;
    
    +(AudioStreamer *)sharedStreamer{
        return sharedStreamer;
    }
    -(void)play{
        playing=YES;
    }
    
    -(void)stop{
        playing=NO;
    }    
    
    -(IBAction)playStop{
        if (!self.playing)
        {       
            [self createStreamer];
            [[MyClass sharedStreamer] start];
        }
        else
        {
            [[MyClass sharedStreamer] stop];
        }
    
    }    
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        if([MyClass sharedStreamer]){
            [[NSNotificationCenter defaultCenter]
             addObserver:self
             selector:@selector(playbackStateChanged:)
             name:ASStatusChangedNotification
             object:[MyClass sharedStreamer]];
            [self playbackStateChanged:nil];
        }
    }
    
    //
    // createStreamer
    //
    // Creates or recreates the AudioStreamer object.
    //
    - (void)createStreamer{
        if ([MyClass sharedStreamer]){
            return;
        }
    
        [self destroyStreamer];
    
        NSString *escapedValue =
        [(NSString *)CFURLCreateStringByAddingPercentEscapes(
                                                                 nil,
                                                             (CFStringRef)@"http://url.com"],
                                                             NULL,
                                                             NULL,
                                                             kCFStringEncodingUTF8)
         autorelease];
    
        NSURL *url = [NSURL URLWithString:escapedValue];
        sharedStreamer = [[AudioStreamer alloc] initWithURL:url];
    
        [[NSNotificationCenter defaultCenter]
         addObserver:self
         selector:@selector(playbackStateChanged:)
         name:ASStatusChangedNotification
         object:[MyClass sharedStreamer]];
    }
    
    //
    // playbackStateChanged:
    //
    // Invoked when the AudioStreamer
    // reports that its playback status has changed.
    //
    - (void)playbackStateChanged:(NSNotification *)aNotification {
        if ([[MyClass sharedStreamer] isWaiting]){
            playing = YES ;
        } else if ([[MyClass sharedStreamer] isPlaying]) {
            playing = YES;
        } else if ([[MyClass sharedStreamer] isIdle]) {
            playing = NO;
                [self destroyStreamer];
        }
    }
    
    //
    // destroyStreamer
    //
    // Removes the streamer, the UI update timer and the change notification
    //
    - (void)destroyStreamer{
        if ([MyClass sharedStreamer]){
            [[NSNotificationCenter defaultCenter]
             removeObserver:self
             name:ASStatusChangedNotification
             object:[MyClass sharedStreamer]];
    
            [[MyClass sharedStreamer] stop];
            [sharedStreamer release];
            sharedStreamer = nil;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to port an application that plays chiptunes (NSF, SPC, etc) music files
Possible Duplicate: accelerometer in Android emulator I have an application that plays music when
I have made a Android streaming application that plays media from online URL's. For
I have an application that plays video files. I have been using code for
My application plays audio stream Here the code: MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
I've got a c# application that plays simple wav files through directsound. With the
I have an application that loads external SWF files and plays them inside a
I've got an application that uses DirectShow/DirectSound which plays videos and extracts the video/sound.
Hi I am trying to write an application that will play morse code. I
I'm working on an online PHP application that has a need for delayed PHP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.