0

Env: win10,vs2015,adobe flash 26,.net framework 4.

I try to load video-js-swf in MFC application in 'ActiveX' way.I alread load the .swf file with code in MFC.

CString str = _T("path.swf");
m_flash.LoadMovie(0, str);

But I can't use m_flash.CallFunction() to call the function inside .swf file,here is my code:

CString temp = _T("<invoke name=\"vjs_getProperty\" returntype=\"xml\"><arguments><string>defaultPlaybackRate</string></arguments></invoke>");
CString test = m_flash.CallFunction(temp);

the .swf project main code as: VideoJS.as

Do anyone know how to solve this problem?How can I call function inside .swf?

Jeff Q
  • 1
  • 2
  • Edit your question instead of adding info as comment. – Kalle Richter Feb 27 '18 at 04:17
  • There are two options, I think. First, knowing the nature of Flash content, it could be loaded but not yet ready. Thus, Flash content must probably signal first that it is ready. Second, you probably need to use **ExternalInterface** class to expose methods to the environment outside the Flash content. – Organis Feb 27 '18 at 15:40

1 Answers1

0

I think I figure it out.It's all about the xml string. In my case, I use:

CString temp = _T("<invoke name=\"vjs_getProperty\" returntype=\"xml\"><arguments><string>defaultPlaybackRate</string></arguments></invoke>");
CString test = m_flash.CallFunction(temp);

It's report an error.But when I use:

CString temp = _T(R"(<invoke name="vjs_getProperty" returntype="xml"><arguments><string>defaultPlaybackRate</string></arguments></invoke>)");
CString test = m_flash.CallFunction(temp);

or:

CString temp = _T(R"(<invoke name="vjs_getProperty" returntype="xml"><arguments><string>!CDATA[[defaultPlaybackRate]]</string></arguments></invoke>)");
CString test = m_flash.CallFunction(temp);

It's OK. I think the problem is the flash xml parser.The parser analyzes the string in strange way.By the way, seems <arguments></arguments> must in same line.

However, There is a new bug, memory leak. In visual studio debug mode,the application can't exit normally. Fix memory leak bug: change the code

https://github.com/videojs/video-js-swf/blob/master/src/com/videojs/providers/RTMPVideoProvider.as (line:349)

if(_isPlaying){
     _ns.close();
     _isPlaying = false;
     _hasEnded = true;
     _reportEnded = true;
     _model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_CLOSE, {}));
    _throughputTimer.stop();
    _throughputTimer.reset();
}

REPLACE by

if(_isPlaying){
    _ns.close();
    _videoReference.attachNetStream(null);
    _isPlaying = false;
    _hasEnded = true;
    _reportEnded = true;
    _model.broadcastEvent(new VideoPlaybackEvent(VideoPlaybackEvent.ON_STREAM_CLOSE, {}));
    _throughputTimer.stop();
    _throughputTimer.reset();
    _videoReference.clear();
    _nc.close();
}

THEN

complie to .SWF file

Jeff Q
  • 1
  • 2