Use the gstreamer plug-in playbin to develop a simple Media Player for video and music.

Source: Internet
Author: User
Tags gstreamer

Source: http://blog.163.com/lixiangqiu_9202/blog/static/535750372012111911544314/

First, install the gstreamer development environment.

Search for installation instructions

The following is a simple example, with some Codes commented out by me.

Some part of the commented-out code is used during my practice, and some parts are set to set the URI path for opening the file.

However, after this setting, you will not be able to play the media from the network, so comment it out.

The code below

# Include <GST/GST. h>
# Include <string. h>
Void error_quit (ststbus * bus, ststmessage * message, gmainloop * loop)
{
Gerror * error;
Ststst_message_parse_error (message, & error, null );
Printf ("error: % s \ n", error-> message );
G_main_loop_quit (loop );
}
Void end_of_streamer (ststbus * bus, ststmessage * message, gmainloop * loop)
{
Printf ("End of streamer... \ n ");
G_main_loop_quit (loop );
}
Void print_pos (maid * pipe)
{
Ststformat fm = maid;
Gint64 POs, Len;
Ststst_element_query_position (pipe, & FM, & Pos );
Ststst_element_query_duration (pipe, & FM, & Len );
Printf ("Time: % u: % 02u: % 02u/% u: % 02u: % 02u: % 02u \ n", maid (POS), maid (LEN ));
}
Int main (INT argc, char ** argv)
{
Gmainloop * loop;
Gstelement * playpipe;
// Stststelement * source;
Gstbus * bus;
// Gchar * file_name;
Gst_init (& argc, & argv );
Loop = g_main_loop_new (null, false );
Playpipe = maid ("playbin", "Play-source ");
// Playpipe = maid ("Play-pipe ");
// Maid (playpipe), source );
// Maid (playpipe, source );
// G_object_set (g_object (playpipe), "location", argv [1], null );
// File_name = malloc (sizeof (gchar) * 7 + strlen (argv [1]) + 1 );
// Strcpy (file_name, "file ://");
// Strcat (file_name, argv [1]);
G_object_set (g_object (playpipe), "Uri", argv [1], null );
Bus = maid (maid ));
Ststst_bus_add_signal_watch (bus );
G_signal_connect (g_object (bus), "message: error", g_callback (error_quit), loop );
G_signal_connect (g_object (bus), "message: EOS", g_callback (end_of_streamer), loop );
Printf ("start... \ n ");
Ststst_element_set_state (playpipe, ststst_state_playing );
G_timeout_add (1000, (void *) print_pos, playpipe );
G_main_loop_run (loop );
Ststst_element_set_state (playpipe, ststst_state_null );
Return 0;
}

Compile

Gcc-O playbin. c 'pkg-config -- cflags -- libs gstreamer-0.10'

Note: The media path is set as follows:

#./Playbin file: // root/Media/Jiangnan. Avi

Gstreamer supports "file: // <path>/<File>", "http: // To enable the source component or the receiving component to support a specific URI, use the stst_element_make_from_uri () function.
The source component uses the stst_uri_src type, and the receiving component uses the stst_uri_sink type.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.