iOS Question [SOLVED] VideoPlayer - song title

Livio F

Member
Licensed User
Longtime User
Hello everybody..
How read the song title directly from the video player stream (Icy Info)?

same as exoplayer musaso :

 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It was not simple, but I got it working:
B4X:
Sub Process_Globals
    Public App As Application
    Public NavControl As NavigationController
    Private Page1 As Page
    Private VideoPlayer1 As VideoPlayer
End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")
    Page1.RootPanel.LoadLayout("1")
    NavControl.ShowPage(Page1)
    VideoPlayer1.LoadVideoUrl("https://stream.radioparadise.com/aac-24")
    Wait For VideoPlayer1_Ready (Success As Boolean)
    If Success Then
        Dim Player As NativeObject = VideoPlayer1.As(NativeObject).GetField("controller").GetField("player")
        Dim PlayerItem As NativeObject = Player.GetField("currentItem")
        Dim Metadata As NativeObject
        Metadata = Metadata.Initialize("AVPlayerItemMetadataOutput").RunMethod("alloc", Null).RunMethod("initWithIdentifiers:", Array(Null))
        Me.As(NativeObject).RunMethod("setDelegate::", Array(Metadata, VideoPlayer1))
        PlayerItem.RunMethod("addOutput:", Array(Metadata))
        VideoPlayer1.Play 'to start playing automatically
    End If
End Sub


Private Sub VideoPlayer1_Metadata(Groups As Object)
    For Each MetadataGroup As NativeObject In Groups.As(List)
        For Each item As NativeObject In MetadataGroup.GetField("items").As(List)
            Log("Key: " & item.GetField("key").AsString)
            Log("Value: " & item.GetField("value").AsString)
        Next
    Next
End Sub


#if OBJC
- (void)setDelegate:(AVPlayerItemMetadataOutput*)meta :(B4IVideoPlayer*)player {
    [meta setDelegate:player queue:dispatch_get_main_queue()];
}
@end
@interface B4IVideoPlayer (AVPlayerItemMetadataOutputPushDelegate) <AVPlayerItemMetadataOutputPushDelegate>
@end
@implementation B4IVideoPlayer (AVPlayerItemMetadataOutputPushDelegate)
- (void)metadataOutput:(AVPlayerItemMetadataOutput *)output
didOutputTimedMetadataGroups:(NSArray<AVTimedMetadataGroup *> *)groups
   fromPlayerItemTrack:(AVPlayerItemTrack *)track {
        NSLog(@"metadataOutput");
     [B4IObjectWrapper raiseUIEvent:[self valueForKey:@"controller"] :@"_metadata:" :@[groups]];
   }
#End If

Key: StreamTitle
Value: David Gray - Mutineers
Key: StreamUrl
Value: http://img.radioparadise.com/covers/l/B00JEBHY14.jpg
 
Upvote 0
Top