iOS Question MediaPLayer initWithContentsOfURL

Discussion in 'iOS Questions' started by narek adonts, Apr 8, 2015.

  1. narek adonts

    narek adonts Well-Known Member Licensed User

    Hi,

    How can I initialize the MediaPlayer with initWithContentsOfURL.

    Narek
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    It is not useful as the native media player doesn't support audio streaming. You should instead use a hidden VideoView.
     
  3. narek adonts

    narek adonts Well-Known Member Licensed User

    I am loading an audio with NSURL from ipod-library.

    I am trying this sub

    Code:
    -(AVAudioPlayer*)MPlayer: (NSString*)url
    {

    NSURL*nURL=[NSURL URLWithString:url];
    //NSError *err;
    AVAudioPlayer *avAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:nURL error:nil] ;
    //
    if( err!=nil )
    //{
    //  NSLog(@
    "Error");
    //
    }
    //avAudioPlayer.numberOfLoops = -1; //infinite
    NSLog(url);
    // Play that t


            

    [avAudioPlayer prepareToPlay] ;
    //[avAudioPlayer play];
    //[avAudioPlayer setVolume:0.5];
    B4IMediaPlayer*bMP;
    bMP.object=avAudioPlayer;
    return avAudioPlayer;
    }

    to set my MediaPlayer with the one that i created but it doesnt play.

    I saw on internet that I need to add @property

    @property (nonatomic,strong) AVAudioPlayer *avAudioPlayer;


    but I dont know how to add a property as it doesnt compile when I add it.
     
  4. narek adonts

    narek adonts Well-Known Member Licensed User

    Solved . I put my mediaplayer inn Process_globals and it works.
    But will be glad to know how to add a property
     
  5. narek adonts

    narek adonts Well-Known Member Licensed User

    this could be a code snippet to play audio from URL ))
     
    valentino s likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice