iOS Question VideoView

moster67

Expert
Licensed User
I have been testing VideoView for the past hours and it works fine.

I have only one problem and one wish:
EDIT: problem resolved. I had to set NavigationBarVisible to false and that resolved my problem. I have adjusted my code below accordingly.

Problem (using LandscapeRight orientation)
-when the streaming starts, the video is not full screen. It seems that a part of the bottom is missing. However, when I tap on the bottom to enable the controls, then the video becomes full-screen. If I disable the controls, I cannot get the stream to go full screen. If I use the Page1_Resize(...) sub and change the videoview-size, then it is better but not full screen. Obviously I am doing something wrong here. Can someone help?


Here is the code:

B4X:
'Code module
#Region  Project Attributes
    #ApplicationLabel: B4i videoview test
    #Version: 1.0.0
    'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
    #iPhoneOrientations: LandscapeRight
    #iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
#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 NavControl As NavigationController
    Private Page1 As Page
    Private vv As VideoView


End Sub

Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    Page1.Initialize("Page1")

    Page1.RootPanel.Color = Colors.White

    vv.Initialize("vv")
    Page1.RootPanel.AddView(vv.View,0,0dip,100%x,100%y)
    'vv.ShowControls = False


    Dim myurl As String = "http://a1408.g.akamai.net/5/1408/1388/2005110405/1a1a1ad948be278cff2d96046ad90768d848b41947aa1986/sample_mpeg4.mp4"
    Dim myurl2 As String ="http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8"
    Dim myurl3 As String = "http://192.168.1.5:8001/1:0:1:3:3DE:110:820000:0:0:0:"
    Dim myurl4 As String  = "http://www.playon.tv/online/iphone5/main.m3u8"
    vv.LoadVideoUrl(myurl4)

  
    NavControl.NavigationBarVisible = False 'permits fullscreen
    'NavControl.ToolBarVisible = False ''permits fullscreen (maybe not needed)
    NavControl.ShowPage(Page1)


End Sub
Sub vv_Ready
    Log(vv.Duration)
    vv.Play
End Sub
Sub vv_Complete
    Log("stream finished")
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
'    vv.View.Width = Width
'    vv.View.Height = Height
End Sub

Private Sub Application_Active

End Sub

Private Sub Application_Inactive

End Sub

Private Sub Application_Background

End Sub

For testing, myUrl4 is the best one although it requires more bandwidth.
Note: iMedia-library must be selected in the library-tab to run this example.

Wish:
-I have some problems with some streams. I think the MPMoviePlayerController class (which I believe you are wrapping) exposes two logs: accessLog and errorLog which could be useful for me to understand better what is happening. Any chance they can be added to the VideoView?

Thanks!
 
Last edited:

moster67

Expert
Licensed User
Problem resolved: I had to set NavigationBarVisible and ToolBarVisible to false and that resolved my problem.
You can consider above code as a tutorial for VideoView if you want :)

However, my wish remains......;)
 
Last edited:
Upvote 0

moster67

Expert
Licensed User
Unfortunately I am unable to obtain the logs using the NativeObject as suggested above. For instance using:

B4X:
Dim accessLog As NativeObject = vvo.GetField("player").GetField("accessLog")

I keep getting the following error:

B4X:
[<MPMoviePlayerController 0x145b75e0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key accessLog.

I think it might be me who does not know how to use and apply the code properly. Could you give an example? Thanks.
 
Upvote 0

Erel

Administrator
Staff member
Licensed User
This code works:
B4X:
Sub vv_Ready
   Dim vvo As NativeObject = vv
   Dim accessLog As NativeObject = vvo.GetField("player").RunMethod("accessLog", Null)
   Dim errorLog As NativeObject = vvo.GetField("player").RunMethod("errorLog", Null)
   Dim data As Object = accessLog.GetField("extendedLogData")
   Dim arr() As Byte = accessLog.NSDataToArray(data)
   Log(BytesToString(arr, 0, arr.Length, "UTF8"))
   data = errorLog.GetField("extendedLogData")
   Dim arr() As Byte = accessLog.NSDataToArray(data)
   Log(BytesToString(arr, 0, arr.Length, "UTF8"))
End Sub
However you will need to wait for the next update as NSDataToArray is a new method.
 
Upvote 0

moster67

Expert
Licensed User
However you will need to wait for the next update as NSDataToArray is a new method.

Any chance that in the meantime I can modify one of the local xml-files adding NSDataToArray as a new method to let me test this? ;)
 
Upvote 0

moster67

Expert
Licensed User
Thank you Erel. Your supplied code now works fine.

However, I think one of my problem with a certain stream takes place before the event "ready" triggers and therefore I cannot trace it. I think I will need to access some constants such as MPMovieLoadState or similar and also related Notifications to understand better the problem.

The NativeObject is probably the way to go. Therefore I'd like to play around with it in the next days since using it I can perhaps add other (currently) missing methods (such as aspect ratio) and perhaps even the streaming authentication (which I will need). Referring to the docs of MPMoviePlayerController, maybe I can obtain what I need.

In this regard, I am wondering if the B4i-events "Ready" and "Complete" are what the docs refer to Notifications in iOS? If yes, is it possible to create my own events (Notifications) in my B4i-code using the NativeObject?

Something similar to what you did here with JavaObject:
http://www.basic4ppc.com/android/forum/threads/adding-an-error-event-to-videoview.42545/#post-257361

If so, could you show an example? Based upon that I can experiment with NativeObject and see what I can do.
 
Last edited:
Upvote 0

Erel

Administrator
Staff member
Licensed User
There is a new method in NativeObject named CreateBlock. This method creates an Objective C block that raises a sub.

You can use it to register for notifications:
B4X:
Private Sub Application_Start (Nav As NavigationController)
   NavControl = Nav
   Page1.Initialize("Page1")
   Page1.Title = "Page 1"
   Page1.RootPanel.Color = Colors.White
   NavControl.ShowPage(Page1)
   Dim no As NativeObject
   Dim block1 As Object = no.CreateBlock("Notification", 1, True)
   no.Initialize("NSNotificationCenter").RunMethod("defaultCenter", Null) _
     .RunMethod("addObserverForName:object:queue:usingBlock:", _
       Array (Null, NavControl, Null, block1))
End Sub

Sub Notification_Event (Args() As Object) As Object
   Log("Notification: " & Args(0))
   Return Null
End Sub
In this example we listen to all the notifications coming from NavControl.
 

Attachments

  • iCore.zip
    30.7 KB · Views: 170
Upvote 0
Top