Beispiel #1
0
int get_media_duration()
{
	if(mediaplay != NULL)
	{
		libvlc_media_parse(media_handle);
		return libvlc_media_get_duration(media_handle);
	}
	return -1;
}
static void
vlc_player_load_media(GtkVlcPlayer *player, libvlc_media_t *media)
{
	libvlc_media_parse(media);
	libvlc_media_player_set_media(player->priv->media_player, media);

	/* NOTE: media was parsed so get_duration works */
	update_length(player, (gint64)libvlc_media_get_duration(media));
	update_time(player, 0);
}
Beispiel #3
0
	MediaMeta VLCWrapper::GetItemMeta (int row, const QString& location) const
	{
		MediaMeta meta;
		auto m = libvlc_media_list_item_at_index (List_.get (), row);
		if (!m)
			return meta;

		if (!QUrl (location).scheme ().isEmpty ())
		{
			meta.Artist_ = tr ("Internet stream");
			meta.Title_ = location;
			return meta;
		}

		libvlc_media_parse (m);
		meta.Artist_ = QString::fromUtf8 (libvlc_media_get_meta (m, libvlc_meta_Artist));
		meta.Album_ = QString::fromUtf8 (libvlc_media_get_meta (m, libvlc_meta_Album));
		meta.Title_ = QString::fromUtf8 (libvlc_media_get_meta (m, libvlc_meta_Title));
		meta.Genre_ = QString::fromUtf8 (libvlc_media_get_meta (m, libvlc_meta_Genre));
		meta.Date_ = libvlc_media_get_meta (m, libvlc_meta_Date);
		meta.Length_ = libvlc_media_get_duration (m) / 1000;

		if (location.isNull ())
			meta.Location_ = QUrl (libvlc_media_get_mrl (m));
		else
			meta.Location_ = QUrl (location);

		libvlc_media_track_info_t *pTrackInfo;
		int numOfStream = libvlc_media_get_tracks_info (m, &pTrackInfo);

		if (numOfStream >= 1)
			meta.Type_ = pTrackInfo->i_type;

		meta.TrackNumber_ = QString (libvlc_media_get_meta (m,
						libvlc_meta_TrackNumber))
				.toInt ();
		return meta;
	}
jobjectArray read_track_info_internal(JNIEnv *env, jobject thiz, libvlc_media_t* p_m)
{
    /* get java class */
    jclass cls = (*env)->FindClass( env, "org/videolan/libvlc/TrackInfo" );
    if ( !cls )
    {
        LOGE("Failed to load class (org/videolan/libvlc/TrackInfo)" );
        return NULL;
    }

    /* get java class contructor */
    jmethodID clsCtor = (*env)->GetMethodID( env, cls, "<init>", "()V" );
    if ( !clsCtor )
    {
        LOGE("Failed to find class constructor (org/videolan/libvlc/TrackInfo)" );
        return NULL;
    }

    /* Get the tracks information of the media. */
    libvlc_media_track_t **p_tracks;

    int i_nbTracks = libvlc_media_tracks_get(p_m, &p_tracks);
    jobjectArray array = (*env)->NewObjectArray(env, i_nbTracks + 1, cls, NULL);

    unsigned i;
    if (array != NULL)
    {
        for (i = 0; i <= i_nbTracks; ++i)
        {
            jobject item = (*env)->NewObject(env, cls, clsCtor);
            if (item == NULL)
                continue;
            (*env)->SetObjectArrayElement(env, array, i, item);

            // use last track for metadata
            if (i == i_nbTracks)
            {
                setInt(env, item, "Type", 3 /* TYPE_META */);
                setLong(env, item, "Length", libvlc_media_get_duration(p_m));
                setString(env, item, "Title", libvlc_media_get_meta(p_m, libvlc_meta_Title));
                setString(env, item, "Artist", libvlc_media_get_meta(p_m, libvlc_meta_Artist));
                setString(env, item, "Album", libvlc_media_get_meta(p_m, libvlc_meta_Album));
                setString(env, item, "Genre", libvlc_media_get_meta(p_m, libvlc_meta_Genre));
                setString(env, item, "ArtworkURL", libvlc_media_get_meta(p_m, libvlc_meta_ArtworkURL));
                continue;
            }

            setInt(env, item, "Id", p_tracks[i]->i_id);
            setInt(env, item, "Type", p_tracks[i]->i_type);
            setString(env, item, "Codec", (const char*)vlc_fourcc_GetDescription(0,p_tracks[i]->i_codec));
            setString(env, item, "Language", p_tracks[i]->psz_language);
            setInt(env, item, "Bitrate", p_tracks[i]->i_bitrate);

            if (p_tracks[i]->i_type == libvlc_track_video)
            {
                setInt(env, item, "Height", p_tracks[i]->video->i_height);
                setInt(env, item, "Width", p_tracks[i]->video->i_width);
                setFloat(env, item, "Framerate", (float)p_tracks[i]->video->i_frame_rate_num / p_tracks[i]->video->i_frame_rate_den);
            }
            if (p_tracks[i]->i_type == libvlc_track_audio)
            {
                setInt(env, item, "Channels", p_tracks[i]->audio->i_channels);
                setInt(env, item, "Samplerate", p_tracks[i]->audio->i_rate);
            }
        }
    }

    libvlc_media_tracks_release(p_tracks, i_nbTracks);
    return array;
}
Beispiel #5
0
void MediaPlayer::_evt_timechanged(int current)
{
	//Need to see how expensive libvlc_media_get_duration actually is, and if we should tone down how
	//often we call it.
	emit timeChanged(current,libvlc_media_get_duration(vlcMedia));
}
Beispiel #6
0
void
AudioOutput::setCurrentSource( MediaStream* stream )
{
    tDebug() << Q_FUNC_INFO;

    setState( Loading );

    if ( m_vlcMedia != nullptr )
    {
        // Ensure playback is stopped, then release media
        libvlc_media_player_stop( m_vlcPlayer );
        libvlc_media_release( m_vlcMedia );
        m_vlcMedia = nullptr;
    }
    if ( m_autoDelete && m_currentStream != nullptr )
    {
        delete m_currentStream;
    }

    m_currentStream = stream;
    m_totalTime = 0;
    m_currentTime = 0;
    m_justSeeked = false;
    m_seekable = true;

    QByteArray url;
    switch ( stream->type() )
    {
        case MediaStream::Unknown:
            tDebug() << Q_FUNC_INFO << "MediaStream Type is Invalid:" << stream->type();
            break;

        case MediaStream::Empty:
            tDebug() << Q_FUNC_INFO << "MediaStream is empty.";
            break;

        case MediaStream::Url:
            tDebug() << Q_FUNC_INFO << "MediaStream::Url:" << stream->url();
            if ( stream->url().scheme().isEmpty() )
            {
                url = "file:///";
                if ( stream->url().isRelative() )
                {
                    url.append( QFile::encodeName( QDir::currentPath() ) + '/' );
                }
            }
            url += stream->url().toEncoded();
            break;

        case MediaStream::Stream:
        case MediaStream::IODevice:
            url = QByteArray( "imem://" );
            break;
    }

    tDebug() << Q_FUNC_INFO << "MediaStream::Final Url:" << url;

    m_vlcMedia = libvlc_media_new_location( m_vlcInstance, url.constData() );
    libvlc_event_manager_t* manager = libvlc_media_event_manager( m_vlcMedia );
    libvlc_event_type_t events[] = {
        libvlc_MediaDurationChanged,
    };
    const int eventCount = sizeof(events) / sizeof( *events );
    for ( int i = 0; i < eventCount; i++ )
    {
        libvlc_event_attach( manager, events[ i ], &AudioOutput::vlcEventCallback, this );
    }

    libvlc_media_player_set_media( m_vlcPlayer, m_vlcMedia );

    if ( stream->type() == MediaStream::Url )
    {
        m_totalTime = libvlc_media_get_duration( m_vlcMedia );
    }
    else if ( stream->type() == MediaStream::Stream || stream->type() == MediaStream::IODevice )
    {
        libvlc_media_add_option_flag(m_vlcMedia, "imem-cat=4", libvlc_media_option_trusted);
        const char* imemData = QString( "imem-data=%1" ).arg( (uintptr_t)stream ).toLatin1().constData();
        libvlc_media_add_option_flag(m_vlcMedia, imemData, libvlc_media_option_trusted);
        const char* imemGet = QString( "imem-get=%1" ).arg( (uintptr_t)&readCallback ).toLatin1().constData();
        libvlc_media_add_option_flag(m_vlcMedia, imemGet, libvlc_media_option_trusted);
        const char* imemRelease = QString( "imem-release=%1" ).arg( (uintptr_t)&readDoneCallback ).toLatin1().constData();
        libvlc_media_add_option_flag(m_vlcMedia, imemRelease, libvlc_media_option_trusted);
        const char* imemSeek = QString( "imem-seek=%1" ).arg( (uintptr_t)&MediaStream::seekCallback ).toLatin1().constData();
        libvlc_media_add_option_flag(m_vlcMedia, imemSeek, libvlc_media_option_trusted);
    }
    if ( qApp->arguments().contains( "--chromecast-ip" ) )
    {
        // This is very basic chromecast support through VLC 3+.
        // Totally unstable, unusable and will suck more CPU than you can think of.
        // If you want to improve this, please talk to the guys in #videolan and
        // support them.
        //
        // Knonw problems:
        // 1. It does not work eventhough the IP is correct.
        //    -> Open vlc with the same commandline and accept the Certificate in the VLC UI.
        if ( qApp->arguments().length() > qApp->arguments().indexOf( "--chromecast-ip" ) + 1 )
        {
            QString castIP = qApp->arguments().at( qApp->arguments().indexOf( "--chromecast-ip" ) + 1 );
            QString sout( ":sout=#transcode{vcodec=none,acodec=vorb,ab=320,channels=2,samplerate=44100}:chromecast{ip=%1,mux=webm}" );
            libvlc_media_add_option( m_vlcMedia, sout.arg( castIP ).toLatin1().constData() );
        }
        else
        {
            tLog() << Q_FUNC_INFO << "Chromecast option but no IP supplied.";
        }
    }

//    setState( Stopped );
}
Beispiel #7
0
Omm::AvStream::Meta*
VlcTagger::tag(const std::string& uri)
{
    LOGNS(Omm::Av, upnpav, debug, "vlc tagger tagging: " + uri);

    VlcMeta* pMeta = new VlcMeta;

#if LIBVLC_VERSION_INT < 0x110
    _pVlcMedia = libvlc_media_new(_pVlcInstance, uri.c_str(), _pException);
#else
    _pVlcMedia = libvlc_media_new_location(_pVlcInstance, uri.c_str());
#endif
    handleException();

#if LIBVLC_VERSION_INT < 0x110
#else
    libvlc_media_parse(_pVlcMedia);
#endif

#if LIBVLC_VERSION_INT < 0x110
    char* pTitle = libvlc_media_get_meta(_pVlcMedia, libvlc_meta_Title, _pException);
#else
    char* pTitle = libvlc_media_get_meta(_pVlcMedia, libvlc_meta_Title);
#endif
    handleException();
    if (pTitle) {
        pMeta->setTag("title", std::string(pTitle));
    }

#if LIBVLC_VERSION_INT < 0x110
    char* pArtist = libvlc_media_get_meta(_pVlcMedia, libvlc_meta_Artist, _pException);
#else
    char* pArtist = libvlc_media_get_meta(_pVlcMedia, libvlc_meta_Artist);
#endif
    handleException();
    if (pArtist) {
        pMeta->setTag("artist", std::string(pArtist));
    }

#if LIBVLC_VERSION_INT < 0x110
    char* pAlbum = libvlc_media_get_meta(_pVlcMedia, libvlc_meta_Album, _pException);
#else
    char* pAlbum = libvlc_media_get_meta(_pVlcMedia, libvlc_meta_Album);
#endif
    handleException();
    if (pAlbum) {
        pMeta->setTag("album", std::string(pAlbum));
    }

#if LIBVLC_VERSION_INT < 0x110
    char* pTrack = libvlc_media_get_meta(_pVlcMedia, libvlc_meta_TrackNumber, _pException);
#else
    char* pTrack = libvlc_media_get_meta(_pVlcMedia, libvlc_meta_TrackNumber);
#endif
    handleException();
    if (pTrack) {
        pMeta->setTag("track", std::string(pTrack));
    }

#if LIBVLC_VERSION_INT < 0x110
    libvlc_time_t duration = libvlc_media_get_duration(_pVlcMedia, _pException);
#else
    libvlc_time_t duration = libvlc_media_get_duration(_pVlcMedia);
#endif
    handleException();
    if (duration) {
        pMeta->setTag("duration", Poco::NumberFormatter::format(duration));
    }

    libvlc_media_release(_pVlcMedia);

    // vlc libs need to play the data in order to analyse the streams
    // thus we make a simple filename based media type detection
    Poco::Path path(uri);
    // try to get a filename extension for type of media
    std::string extension = Poco::toLower(path.getExtension());
//    LOGNS(Omm::Av, upnpav, debug, "vlc tagger extension: " + extension);

    Omm::AvStream::Meta::ContainerFormat containerFormat = Omm::AvStream::Meta::CF_UNKNOWN;
    if (extension == "mp3") {
        pMeta->_mime = Omm::Av::Mime::AUDIO_MPEG;
        containerFormat = Omm::AvStream::Meta::CF_AUDIO;
    }
    else if (extension == "wma" || extension == "ogg" || extension == "wav") {
        pMeta->_mime = Omm::Av::Mime::TYPE_AUDIO;
        containerFormat = Omm::AvStream::Meta::CF_AUDIO;
    }
    else if (extension == "mp4" || extension == "mpeg" || extension == "mpg") {
        pMeta->_mime = Omm::Av::Mime::VIDEO_MPEG;
        containerFormat = Omm::AvStream::Meta::CF_VIDEO;
    }
    else if (extension == "avi" || extension == "wmv" || extension == "flv") {
        pMeta->_mime = Omm::Av::Mime::TYPE_VIDEO;
        containerFormat = Omm::AvStream::Meta::CF_VIDEO;
    }
    else if (extension == "jpg" || extension == "png" || extension == "gif") {
        pMeta->_mime = Omm::Av::Mime::TYPE_IMAGE;
        containerFormat = Omm::AvStream::Meta::CF_IMAGE;
    }
    else if (extension == "m3u") {
        pMeta->_mime = Omm::Av::Mime::PLAYLIST;
        containerFormat = Omm::AvStream::Meta::CF_PLAYLIST;
    }

    if (containerFormat == Omm::AvStream::Meta::CF_AUDIO) {
        pMeta->_isStillImage = false;
        VlcStreamInfo* pStreamInfo = new VlcStreamInfo;
        pStreamInfo->_isAudio = true;
        pStreamInfo->_isVideo = false;
        pMeta->addStream(pStreamInfo);
    }
    else if (containerFormat == Omm::AvStream::Meta::CF_VIDEO) {
        pMeta->_isStillImage = false;
        VlcStreamInfo* pStreamInfo = new VlcStreamInfo;
        pStreamInfo->_isAudio = false;
        pStreamInfo->_isVideo = true;
        pMeta->addStream(pStreamInfo);
    }
    else if (containerFormat == Omm::AvStream::Meta::CF_IMAGE) {
        pMeta->_isStillImage = true;
        VlcStreamInfo* pStreamInfo = new VlcStreamInfo;
        pStreamInfo->_isAudio = false;
        pStreamInfo->_isVideo = false;
        pMeta->addStream(pStreamInfo);
    }
    else if (containerFormat == Omm::AvStream::Meta::CF_PLAYLIST) {
        pMeta->setIsPlaylist(true);
    }

    return pMeta;
}