iOS Question Audio Streaming issue using AVplayer

Rodrigo Vargas

Member
Licensed User
Hello,

I have a sports app with a "Radio" icon that play an audio stream from shoutcheap:
I was using AVplayer and everything was working fine until some weeks ago (not sure how long). Is not working in any iOS device, but the code didn't change (I actually didn't upgrade de app)

The code is working fine and most of it just makes a "loading" effect in the icon.

The problem is specifically with the line:

B4X:
Player1.RunMethod("play", Null)

There are no errors and playerstatus is actually 1 (Ready to play)

But nothing happens. No sound comming out. Seems like is playing but no sound.
As I said this as been tested in many devices.
The streaming works fine and I tested several streamings.

Wondering if is something related with iOS/AVPlayer that recentrly changed? Any ideas?


Part of the code I'm using for this:

B4X:
Sub Process_Globals
    Dim Player1 As NativeObject
    Dim PlayerStatus As Int    '1 = Ready  0 = Error
    Dim PlayerControl As Int   '1 = IsPlaying   0 = Is Paused
End Sub

Private Sub ImageIconoRadio_Click
    If PlayerControl = 0 Then
        StartStreaming
    Else
        StopStreaming
    End If
End Sub

Private Sub StartStreaming
 
    ImageIconoRadio.Bitmap = LoadBitmap(File.DirAssets,"radio-load0.png")
    LabelRadio.TextColor = Colors.White
 
    Player1 = CreatePlayer("https://cp3.shoutcheap.com:18019/stream")

    ContadorPlayer = 0
    ContadorPlayerSeguridad = 0
    Timer3.Enabled = True

End Sub



Sub Timer3_Tick
    Timer3.Enabled=False

    If ContadorPlayer = 0 Then
        ImageIconoRadio.Bitmap = LoadBitmap(File.DirAssets,"radio-load0.png")
        ContadorPlayer = 1
 
    Else If ContadorPlayer = 1 Then
        ImageIconoRadio.Bitmap = LoadBitmap(File.DirAssets,"radio-load1.png")
        ContadorPlayer = 2
 
    Else If ContadorPlayer = 2 Then
        ImageIconoRadio.Bitmap = LoadBitmap(File.DirAssets,"radio-load2.png")
        ContadorPlayer = 3
             
    Else If ContadorPlayer = 3 Then
        ImageIconoRadio.Bitmap = LoadBitmap(File.DirAssets,"radio-load3.png")
        ContadorPlayer = 0
    End If

    ContadorPlayerSeguridad = ContadorPlayerSeguridad + 1
 
    If ContadorPlayerSeguridad = 50 Then
        StopStreaming
    Else
        Timer3.Enabled=True
    End If
 
    PlayerStatus = Player1.GetField("status").AsNumber
 
    Log(PlayerStatus)
 
    If PlayerStatus = 1 And ContadorPlayerSeguridad > 5 Then
     
        Player1.RunMethod("play", Null)
     
        PlayerControl = 1
        Timer3.Enabled = False
        ImageIconoRadio.Bitmap = LoadBitmap(File.DirAssets,"iconoradio2selected.png")
        ContadorPlayer = 0
    End If

End Sub
 
Last edited:

Rodrigo Vargas

Member
Licensed User
OK, I made a test as suggested (see code below).
I tried with different streams from different providers. None is working.
Also I reissued the certificates just to make sure.

Same results: Audio don't play but seems loading properly. I can't see any error.

Q: Is there any other alternative to play a streaming in iOS?

Thanks in advance !

B4X:
'Code module
#Region  Project Attributes

    #ApplicationLabel: AudioTest
    #Version: 3.5.1
   
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: Portrait
    #iPadOrientations: Portrait
    #Target: iPhone, iPad
    #ATSEnabled: False
    #MinVersion: 12
    #CertificateFile: ios_distribution.cer
    #ProvisionFile: audiotest.mobileprovision
    '#ProvisionFile: store.mobileprovision
   
#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 xui As XUI
    Private player1 As NativeObject
   
End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.RootPanel.LoadLayout("Page1")
    NavControl.ShowPage(Page1)
    player1 = CreatePlayer("https://cp3.shoutcheap.com:18019/stream")
    player1.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

Sub Button1_Click
    xui.MsgboxAsync("Hello world!", "B4X")
End Sub

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

Rodrigo Vargas

Member
Licensed User
I found some additional problems when using the Video Player to read streamming:

In this thread there is an explanation of how ready event works.
https://www.b4x.com/android/forum/threads/videoplayer-replaces-videoview.86643/

I noticed that it return "true" (success) even when the URL is not working....

This is always true:

B4X:
   Wait For VideoPlayer1_Ready (Success As Boolean)
   If Success Then
     VideoPlayer1.Play 'to start playing automatically
   End If
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've just tested this code and it works fine here:
B4X:
'B4XPages project but it doesn't matter
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    player1 = CreatePlayer("https://cp3.shoutcheap.com:18019/stream")
    player1.RunMethod("play", Null)
End Sub

Private 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
 
Upvote 0

watesoft

Active Member
Licensed User
Longtime User
Maybe you turned off the mute switch!
 

Attachments

  • Screenshot_20231218_224400.jpg
    497.2 KB · Views: 101
Upvote 0

Rodrigo Vargas

Member
Licensed User

Yes, I tried a similar example a few days ago and it works. But as soon as this code is inside the app code it doesn't work. So i guess is related with some apple changes (because the app was working fine and it was published) and probably some conflict with the existing code.

But the solution with VideoPlayer is working and the radio is back, up and running.

Thank you very much for your help.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…