facebook

Manipulate new widget audio

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #344561 Reply

    BryanBudelon
    Member

    Hello people!

    I’m doing tests with widget audio, but have one problem. When create ‘player’ of audio by code, he not play in smartphone, only testing.

    Below is the project:

    Attachments:
    You must be logged in to view attached files.
    #344583 Reply

    BryanBudelon
    Member

    UP!

    #344592 Reply

    support-michael
    Keymaster

    A couple of bugs in your code:

    1) your media url does not work for me. See the screenshot below that shows the media does not load. I tried it outside of the mobione app and it also failed. Switching to a known media stream works.

    2) in a native app you need to wait for the cordova/phonegap api to initialize before you

    
    // I reimplemented your code to respect the requirement that you should not use the Cordova 
    // api until you receive the deviceready event. I also switched to a streaming URL that is
    // very reliable. Avoid wasting time with garbage in, garbage out media sources. Use only sources
    // that are known to work before you start messing with other sources will save everyone time.
    
    /**
     * Called when document is loaded.
     */
    phoneui.documentReadyHandler = function() {
        document.addEventListener("deviceready",onDeviceReady,false);
    }
    
    //var url = 'http://audio.tupa.am.br:9986/;'; // <-- does not load
    var url = 'http://vprbbc.streamguys.net:80/vprbbc24.mp3'; // BBC stream
    var media;
    
    function createMedia() {
        if (media) return;
        media = phoneui.createMedia(url);    
    }
    
    function onDeviceReady() {
        createMedia();
    }
    
    function playStreaming() {
        if (!media) {
            alert('media is  not initialized');
            return;
        }
        media.play();
    }
    
    function stopStreaming() {
        if (media) media.stop();
    }
    #344596 Reply

    BryanBudelon
    Member

    About streaming, he is offline temporarily, but works.

    Another question: Should work in backgroud with this mode, right? But this is not happening.

    Thanks for help! 😀

    #344600 Reply

    support-michael
    Keymaster

    >About streaming, he is offline temporarily, but works.

    The issue I wasted time checking out the stream and it is dead – waste of time. Let’s focus only on reliable services.

    >Should work in backgroud with this mode, right? But this is not happening.

    Depends upon what your definition of background is. If you mean play audio when some other application is running in foreground, then no that is not supported. But if you want the application to play media without the user pressing a play button do something simple like add playStream() as shown below in the deviceready handler:

    function createMedia() {
        if (media) return;
        media = phoneui.createMedia(url);
        playStreaming();
    }
    #344605 Reply

    BryanBudelon
    Member

    I would play audio when some other application is running with widget audio, because
    using this way http://www.genuitec.com/support-genuitec/viewtopic.php?f=14&t=6013
    occurs very delay between the click and start reproducing.

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: Manipulate new widget audio

You must be logged in to post in the forum log in