iOS Question Multiple audio (url) streams at the same time. Possible?

XMan2012

Member
Licensed User
Hello,

I am trying to acheived the same thing I did with B4A (without any problems using the Audio lib).
I want to be able to play 3 audio streams (urls) at the same time, but it seems that with Videoview it's not possible? If not, any alternative?

Here is my code, which does not work with more than 1 stream:
B4X:
'Code module
#Region  Project Attributes
    #ApplicationLabel: B4i Example
    #Version: 1.0.0
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
    #Target: iPhone, iPad
    #MinVersion: 7
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page

    Private start As Button
    Private URLPlayer1 As VideoView
    Private URLPlayer2 As VideoView
    Private URLPlayer3 As VideoView
    Private stop As Button
End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.Title = "Page 1"
    Page1.RootPanel.Color = Colors.Black
    Page1.RootPanel.LoadLayout("xxxx")
    NavControl.ShowPage(Page1)
    URLPlayer1.Initialize("rdev1")
    URLPlayer2.Initialize("rdev2")
    URLPlayer3.Initialize("rdev3")
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
  
End Sub

Private Sub Application_Background
  
End Sub

Sub start_Click
    URLPlayer1.LoadVideoUrl("http://peace.str3am.com:6350")
    URLPlayer2.LoadVideoUrl("http://cast.sc1.shoutcaststreaming.us:8080")
    URLPlayer2.LoadVideoUrl("http://sc1.christiannetcast.com:9058")
End Sub

Sub stop_Click
    URLPlayer1.Stop
    URLPlayer2.Stop
    URLPlayer3.Stop
End Sub
Sub rdev1_Ready
    URLPlayer1.Play
End Sub
Sub rdev1_Complete
    Log("stream1 finished")
End Sub
Sub rdev2_Ready
    URLPlayer2.Play
End Sub
Sub rdev2_Complete
    Log("stream2 finished")
End Sub
Sub rdev3_Ready
    URLPlayer3.Play
End Sub
Sub rdev3_Complete
    Log("stream3 finished")
End Sub
Thank you
 
Last edited:

XMan2012

Member
Licensed User
Thanks Erel. That's too bad. Bought B4i mainly for that instead of having to learn Swift (i did manage to do it a bit using the iOs audio framework). Can you recommend someone from the community that could make me a library that would support that (i would pay if the price is reasonable of course)? You can message me privately if you want.
 
Last edited:

Erel

Administrator
Staff member
Licensed User
Different approach:
B4X:
Sub Process_Globals
   Public App As Application
   Public NavControl As NavigationController
   Private Page1 As Page
   Private player1, player2, player3 As NativeObject
End Sub

Private Sub Application_Start ( Nav As NavigationController)
   NavControl = Nav
   Page1.Initialize("Page1")
   Page1.Title = "Page 1"
   Page1.RootPanel.LoadLayout("1")
   Nav.ShowPage(Page1)
   player1 = CreatePlayer("http://peace.str3am.com:6350")
   player2 = CreatePlayer("http://cast.sc1.shoutcaststreaming.us:8080")
   player3 = CreatePlayer("http://sc1.christiannetcast.com:9058")
   player1.RunMethod("play", Null)
   player2.RunMethod("play", Null)
   player3.RunMethod("play", Null)
End Sub

Sub CreatePlayer(url As String) As NativeObject
   Dim u As NativeObject
   u = u.Initialize("NSURL").RunMethod("URLWithString:", Array(url))
   Dim player As NativeObject
   player = player.Initialize("AVPlayer").RunMethod("alloc", Null) _
     .RunMethod("initWithURL:", Array(u))
   Return player
End Sub
 

XMan2012

Member
Licensed User
Wow! Thank you so much! This is perfect, works well also. I will experiment more with the properties, methods of the AVPlayer object using that idea. Did not realize I could do it this way. Thumbs up for your usual support Erel!

Maybe you could add this by default in B4i (in the future) along with the properties and methods? Well like the mediaplayerstream of B4A basically.
 
Top